Open dreamsxin opened 5 years ago
Yes I saw that earlier on these https://travis-ci.org/phalcon/cphalcon/jobs/548411093#L1439
Something we can fix in Phalcon or is this Zephir based?
@niden Fix in Phalcon
if isset options["included"] {
let included = options["included"];
} elseif isset options["includedMinimum"] {
let included = options["includedMinimum"];
} else {
let included = null;
}
or
var included = null;
If fix in zephir, all variables are initialized by default to NULL, or judge initialization when you use it, but it's more cumbersome.
@dreamsxin I think we should go in that direction: Any scalar type should have its own "default constructor" like in other languages (C++, Golang). In that scenario variables declared without an initial value are set to their zero values:
0
for all integer types: int
, uint
, long
, ulong
, char
, uchar
0.0
for floating point numbers: double
, float
false
for booleans[ ]
for arrays""
for strings: string
, istring
NULL
for resources and variable types: resource
, var
Even more, I would like expect such behavior:
int n;
double d;
var v;
array t = [ n, d, v ];
var_dump(t);
array(3) {
[0]=>
int(0)
[1]=>
float(0)
[2]=>
NULL
}
@sergeyklay Then we have to modify the memory management, judged by the judgment type undef.
#define ZEPHIR_INIT_NVAR(z) \
do { \
if (Z_TYPE_P(z) == IS_UNDEF) { \
zephir_memory_observe(z); \
} else if (Z_REFCOUNTED_P(z) && !Z_ISREF_P(z)) { \
if (Z_REFCOUNT_P(z) > 1) { \
Z_DELREF_P(z); \
} else { \
zval_dtor(z); \
} \
} \
ZVAL_NULL(z); \
} while (0)
See https://github.com/phalcon/cphalcon/pull/14193 @sergeyklay @niden
Will happen
Variable 0x7ffd95e52240 is already observed#0
Zephir code: