diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2019-09-26 12:22:48 +0200 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-09-27 10:11:47 +0200 |
| commit | a66c60cce3cd8878284fb39388080cfb6bac8ff5 (patch) | |
| tree | 417941074c593391c0b61613082b69334e757cf4 /tests | |
| parent | e8d2097bdc467e4ad814e23b406f70c3dc568ff4 (diff) | |
| download | php-git-a66c60cce3cd8878284fb39388080cfb6bac8ff5.tar.gz | |
Throw Error when writing property of non-object
This removes object auto-vivification support.
This also means that we can remove the corresponding special
handling for typed properites: We no longer need to check that a
property is convertible to stdClass if such a conversion might
take place indirectly due to a nested property write.
Additionally OBJ_W style operations now no longer modify the
object operand, and as such we no longer need to treat op1 as a
def in SSA form.
The next step would be to actually compile the whole LHS of OBJ_W
operations in R rather than W mode, but that causes issues with
SimpleXML, whose object handlers depend on the current compilation
structure.
Part of https://wiki.php.net/rfc/engine_warnings.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/classes/implicit_instantiation_001.phpt | 156 | ||||
| -rw-r--r-- | tests/lang/bug24499.phpt | 3 | ||||
| -rw-r--r-- | tests/lang/bug7515.phpt | 8 | ||||
| -rw-r--r-- | tests/lang/engine_assignExecutionOrder_008.phpt | 28 | ||||
| -rw-r--r-- | tests/lang/foreachLoop.016.phpt | 26 | ||||
| -rw-r--r-- | tests/lang/passByReference_006.phpt | 180 |
6 files changed, 43 insertions, 358 deletions
diff --git a/tests/classes/implicit_instantiation_001.phpt b/tests/classes/implicit_instantiation_001.phpt deleted file mode 100644 index 495a8a1e35..0000000000 --- a/tests/classes/implicit_instantiation_001.phpt +++ /dev/null @@ -1,156 +0,0 @@ ---TEST-- -Implicit object instantiation when accessing properties of non-object. ---FILE-- -<?php -class C { - // These values get implicitly converted to objects - public $boolFalse = false; - public $emptyString = ''; - public $null = null; - - // These values do not get implicitly converted to objects - public $boolTrue = true; - public $nonEmptyString = 'hello'; - public $intZero = 0; -} - -$c = new C; -foreach($c as $name => $value) { - echo "\n\n---( \$c->$name )---"; - echo "\n --> Attempting implicit conversion to object using increment...\n"; - $c->$name->prop++; - $c->$name = $value; // reset value in case implicit conversion was successful - - echo "\n --> Attempting implicit conversion to object using assignment...\n"; - $c->$name->prop = "Implicit instantiation!"; - $c->$name = $value; // reset value in case implicit conversion was successful - - echo "\n --> Attempting implicit conversion to object using combined assignment...\n"; - $c->$name->prop .= " Implicit instantiation!"; -} - -echo "\n\n\n --> Resulting object:"; -var_dump($c); - -?> ---EXPECTF-- ----( $c->boolFalse )--- - --> Attempting implicit conversion to object using increment... - -Warning: Creating default object from empty value in %s on line 18 - -Notice: Undefined property: stdClass::$prop in %s on line 18 - - --> Attempting implicit conversion to object using assignment... - -Warning: Creating default object from empty value in %s on line 22 - - --> Attempting implicit conversion to object using combined assignment... - -Warning: Creating default object from empty value in %s on line 26 - -Notice: Undefined property: stdClass::$prop in %s on line 26 - - ----( $c->emptyString )--- - --> Attempting implicit conversion to object using increment... - -Warning: Creating default object from empty value in %s on line 18 - -Notice: Undefined property: stdClass::$prop in %s on line 18 - - --> Attempting implicit conversion to object using assignment... - -Warning: Creating default object from empty value in %s on line 22 - - --> Attempting implicit conversion to object using combined assignment... - -Warning: Creating default object from empty value in %s on line 26 - -Notice: Undefined property: stdClass::$prop in %s on line 26 - - ----( $c->null )--- - --> Attempting implicit conversion to object using increment... - -Warning: Creating default object from empty value in %s on line 18 - -Notice: Undefined property: stdClass::$prop in %s on line 18 - - --> Attempting implicit conversion to object using assignment... - -Warning: Creating default object from empty value in %s on line 22 - - --> Attempting implicit conversion to object using combined assignment... - -Warning: Creating default object from empty value in %s on line 26 - -Notice: Undefined property: stdClass::$prop in %s on line 26 - - ----( $c->boolTrue )--- - --> Attempting implicit conversion to object using increment... - -Warning: Attempt to %s property 'prop' of non-object in %s on line 18 - - --> Attempting implicit conversion to object using assignment... - -Warning: Attempt to assign property 'prop' of non-object in %s on line 22 - - --> Attempting implicit conversion to object using combined assignment... - -Warning: Attempt to assign property 'prop' of non-object in %s on line 26 - - ----( $c->nonEmptyString )--- - --> Attempting implicit conversion to object using increment... - -Warning: Attempt to %s property 'prop' of non-object in %s on line 18 - - --> Attempting implicit conversion to object using assignment... - -Warning: Attempt to assign property 'prop' of non-object in %s on line 22 - - --> Attempting implicit conversion to object using combined assignment... - -Warning: Attempt to assign property 'prop' of non-object in %s on line 26 - - ----( $c->intZero )--- - --> Attempting implicit conversion to object using increment... - -Warning: Attempt to %s property 'prop' of non-object in %s on line 18 - - --> Attempting implicit conversion to object using assignment... - -Warning: Attempt to assign property 'prop' of non-object in %s on line 22 - - --> Attempting implicit conversion to object using combined assignment... - -Warning: Attempt to assign property 'prop' of non-object in %s on line 26 - - - - --> Resulting object:object(C)#%d (6) { - ["boolFalse"]=> - object(stdClass)#%d (1) { - ["prop"]=> - string(24) " Implicit instantiation!" - } - ["emptyString"]=> - object(stdClass)#%d (1) { - ["prop"]=> - string(24) " Implicit instantiation!" - } - ["null"]=> - object(stdClass)#%d (1) { - ["prop"]=> - string(24) " Implicit instantiation!" - } - ["boolTrue"]=> - bool(true) - ["nonEmptyString"]=> - string(5) "hello" - ["intZero"]=> - int(0) -} diff --git a/tests/lang/bug24499.phpt b/tests/lang/bug24499.phpt index 6ce56dbad7..263293391f 100644 --- a/tests/lang/bug24499.phpt +++ b/tests/lang/bug24499.phpt @@ -12,7 +12,8 @@ class Id { } $id = new Id(); -@$obj->foo = "bar"; +$obj = new stdClass; +$obj->foo = "bar"; $id->tester($obj); print_r($obj); ?> diff --git a/tests/lang/bug7515.phpt b/tests/lang/bug7515.phpt index 5c7756c6a1..8927c5df94 100644 --- a/tests/lang/bug7515.phpt +++ b/tests/lang/bug7515.phpt @@ -1,14 +1,13 @@ --TEST-- Bug #7515 (weird & invisible referencing of objects) ---INI-- -error_reporting=2039 --FILE-- <?php class obj { function method() {} } -$o->root=new obj(); +$o = new stdClass; +$o->root = new obj(); ob_start(); var_dump($o); @@ -30,6 +29,5 @@ y=$y "; } ?> ---EXPECTF-- -Warning: Creating default object from empty value in %s on line %d +--EXPECT-- success diff --git a/tests/lang/engine_assignExecutionOrder_008.phpt b/tests/lang/engine_assignExecutionOrder_008.phpt index 310e0d9964..76b0cb1a7c 100644 --- a/tests/lang/engine_assignExecutionOrder_008.phpt +++ b/tests/lang/engine_assignExecutionOrder_008.phpt @@ -29,18 +29,24 @@ echo $a[$i[0][0]=f()][++$i[0][0]]; unset($i); echo "\n" . '$i->p=f(): '; +$i = new stdClass; echo $a[$i->p=f()][++$i->p]; unset($i); echo "\n" . '$i->p->q=f(): '; +$i = new stdClass; +$i->p = new stdClass; echo $a[$i->p->q=f()][++$i->p->q]; unset($i); echo "\n" . '$i->p[0]=f(): '; +$i = new stdClass; echo $a[$i->p[0]=f()][++$i->p[0]]; unset($i); echo "\n" . '$i->p[0]->p=f(): '; +$i = new stdClass; +$i->p[0] = new stdClass; echo $a[$i->p[0]->p=f()][++$i->p[0]->p]; unset($i); @@ -59,28 +65,16 @@ echo "\n" . 'C::$p->q=f(): '; C::$p = new stdclass; echo $a[C::$p->q=f()][++C::$p->q]; ?> ---EXPECTF-- +--EXPECT-- $i=f(): good $$x=f(): good ${'i'}=f(): good $i[0]=f(): good $i[0][0]=f(): good -$i->p=f(): -Warning: Creating default object from empty value in %s on line %d -good -$i->p->q=f(): -Warning: Creating default object from empty value in %s on line %d - -Warning: Creating default object from empty value in %s on line %d -good -$i->p[0]=f(): -Warning: Creating default object from empty value in %s on line %d -good -$i->p[0]->p=f(): -Warning: Creating default object from empty value in %s on line %d - -Warning: Creating default object from empty value in %s on line %d -good +$i->p=f(): good +$i->p->q=f(): good +$i->p[0]=f(): good +$i->p[0]->p=f(): good C::$p=f(): good C::$p[0]=f(): good C::$p->q=f(): good diff --git a/tests/lang/foreachLoop.016.phpt b/tests/lang/foreachLoop.016.phpt index fa1267fa8d..0fc57147d9 100644 --- a/tests/lang/foreachLoop.016.phpt +++ b/tests/lang/foreachLoop.016.phpt @@ -46,6 +46,7 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so unset($a, $b); echo "\n" . '$a->b' . "\n"; + $a = new stdClass; $b = $a->b = array('original'); foreach($a->b as $k=>&$v) { $v = 'changed'; @@ -54,6 +55,8 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so unset($a, $b); echo "\n" . '$a->b->c' . "\n"; + $a = new stdClass; + $a->b = new stdClass; $b = $a->b->c = array('original'); foreach($a->b as $k=>&$v) { $v = 'changed'; @@ -62,6 +65,7 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so unset($a, $b); echo "\n" . '$a->b[0]' . "\n"; + $a = new stdClass; $b = $a->b[0] = array('original'); foreach($a->b[0] as $k=>&$v) { $v = 'changed'; @@ -70,6 +74,7 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so unset($a, $b); echo "\n" . '$a->b[0][0]' . "\n"; + $a = new stdClass; $b = $a->b[0][0] = array('original'); foreach($a->b[0][0] as $k=>&$v) { $v = 'changed'; @@ -78,6 +83,8 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so unset($a, $b); echo "\n" . '$a->b[0]->c' . "\n"; + $a = new stdClass; + $a->b[0] = new stdClass; $b = $a->b[0]->c = array('original'); foreach($a->b[0]->c as $k=>&$v) { $v = 'changed'; @@ -108,6 +115,7 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so unset(C::$a[0], $b); echo "\n" . 'C::$a[0]->b' . "\n"; + C::$a[0] = new stdClass; C::$a[0]->b = array('original'); $b = C::$a[0]->b; foreach(C::$a[0]->b as $k=>&$v) { @@ -116,7 +124,7 @@ Ensure foreach splits the iterated entity from its cow reference set, for all so var_dump($b); unset(C::$a[0]->b, $b); ?> ---EXPECTF-- +--EXPECT-- $a array(1) { [0]=> @@ -148,44 +156,30 @@ array(1) { } $a->b - -Warning: Creating default object from empty value in %s on line %d array(1) { [0]=> string(8) "original" } $a->b->c - -Warning: Creating default object from empty value in %s on line %d - -Warning: Creating default object from empty value in %s on line %d array(1) { [0]=> string(8) "original" } $a->b[0] - -Warning: Creating default object from empty value in %s on line %d array(1) { [0]=> string(8) "original" } $a->b[0][0] - -Warning: Creating default object from empty value in %s on line %d array(1) { [0]=> string(8) "original" } $a->b[0]->c - -Warning: Creating default object from empty value in %s on line %d - -Warning: Creating default object from empty value in %s on line %d array(1) { [0]=> string(8) "original" @@ -204,8 +198,6 @@ array(1) { } C::$a[0]->b - -Warning: Creating default object from empty value in %s on line %d array(1) { [0]=> string(8) "original" diff --git a/tests/lang/passByReference_006.phpt b/tests/lang/passByReference_006.phpt index 25107b47c8..ce5d5ca2af 100644 --- a/tests/lang/passByReference_006.phpt +++ b/tests/lang/passByReference_006.phpt @@ -3,78 +3,54 @@ Pass uninitialised objects and arrays by reference to test implicit initialisati --FILE-- <?php -function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { +function refs(&$ref1, &$ref2) { $ref1 = "Ref1 changed"; $ref2 = "Ref2 changed"; - $ref3 = "Ref3 changed"; - $ref4 = "Ref4 changed"; - $ref5 = "Ref5 changed"; } class C { - function __construct(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + function __construct(&$ref1, &$ref2) { $ref1 = "Ref1 changed"; $ref2 = "Ref2 changed"; - $ref3 = "Ref3 changed"; - $ref4 = "Ref4 changed"; - $ref5 = "Ref5 changed"; } - function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + function refs(&$ref1, &$ref2) { $ref1 = "Ref1 changed"; $ref2 = "Ref2 changed"; - $ref3 = "Ref3 changed"; - $ref4 = "Ref4 changed"; - $ref5 = "Ref5 changed"; } - static function static_refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + static function static_refs(&$ref1, &$ref2) { $ref1 = "Ref1 changed"; $ref2 = "Ref2 changed"; - $ref3 = "Ref3 changed"; - $ref4 = "Ref4 changed"; - $ref5 = "Ref5 changed"; } } echo "\n ---- Pass uninitialised array & object by ref: function call ---\n"; -unset($u1, $u2, $u3, $u4, $u5); -refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); -var_dump($u1, $u2, $u3, $u4, $u5); +unset($u1, $u2); +refs($u1[0], $u2[0][1]); +var_dump($u1, $u2); echo "\n ---- Pass uninitialised arrays & objects by ref: static method call ---\n"; -unset($u1, $u2, $u3, $u4, $u5); -C::static_refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); -var_dump($u1, $u2, $u3, $u4, $u5); +unset($u1, $u2); +C::static_refs($u1[0], $u2[0][1]); +var_dump($u1, $u2); echo "\n\n---- Pass uninitialised arrays & objects by ref: constructor ---\n"; -unset($u1, $u2, $u3, $u4, $u5); -$c = new C($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); -var_dump($u1, $u2, $u3, $u4, $u5); +unset($u1, $u2); +$c = new C($u1[0], $u2[0][1]); +var_dump($u1, $u2); echo "\n ---- Pass uninitialised arrays & objects by ref: instance method call ---\n"; -unset($u1, $u2, $u3, $u4, $u5); -$c->refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); -var_dump($u1, $u2, $u3, $u4, $u5); +unset($u1, $u2); +$c->refs($u1[0], $u2[0][1]); +var_dump($u1, $u2); ?> ---EXPECTF-- - ---- Pass uninitialised array & object by ref: function call --- - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d +--EXPECT-- +---- Pass uninitialised array & object by ref: function call --- array(1) { [0]=> string(12) "Ref1 changed" @@ -86,41 +62,8 @@ array(1) { string(12) "Ref2 changed" } } -object(stdClass)#%d (1) { - ["a"]=> - string(12) "Ref3 changed" -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - string(12) "Ref4 changed" - } -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - object(stdClass)#%d (1) { - ["c"]=> - string(12) "Ref5 changed" - } - } -} ---- Pass uninitialised arrays & objects by ref: static method call --- - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d array(1) { [0]=> string(12) "Ref1 changed" @@ -132,42 +75,9 @@ array(1) { string(12) "Ref2 changed" } } -object(stdClass)#%d (1) { - ["a"]=> - string(12) "Ref3 changed" -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - string(12) "Ref4 changed" - } -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - object(stdClass)#%d (1) { - ["c"]=> - string(12) "Ref5 changed" - } - } -} ---- Pass uninitialised arrays & objects by ref: constructor --- - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d array(1) { [0]=> string(12) "Ref1 changed" @@ -179,41 +89,8 @@ array(1) { string(12) "Ref2 changed" } } -object(stdClass)#%d (1) { - ["a"]=> - string(12) "Ref3 changed" -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - string(12) "Ref4 changed" - } -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - object(stdClass)#%d (1) { - ["c"]=> - string(12) "Ref5 changed" - } - } -} ---- Pass uninitialised arrays & objects by ref: instance method call --- - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d - -Warning: Creating default object from empty value in %spassByReference_006.php on line %d array(1) { [0]=> string(12) "Ref1 changed" @@ -225,24 +102,3 @@ array(1) { string(12) "Ref2 changed" } } -object(stdClass)#%d (1) { - ["a"]=> - string(12) "Ref3 changed" -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - string(12) "Ref4 changed" - } -} -object(stdClass)#%d (1) { - ["a"]=> - object(stdClass)#%d (1) { - ["b"]=> - object(stdClass)#%d (1) { - ["c"]=> - string(12) "Ref5 changed" - } - } -} |
