From 6144da7e351545158db3fad647b818b1027354f7 Mon Sep 17 00:00:00 2001 From: Scott MacVicar Date: Fri, 31 Dec 2010 16:57:45 +0000 Subject: [PATCH] Silently casting an empty string, null or false into an object by adding a property is pretty non-intuitive. If the same value was 1 or true you get a warning and it halts. Since we can't break BC completely (yet) lets bump this from E_STRICT. Also added a new section to UPGRADING for engine changes. baz = 1; var_dump($x); $y = 1; $y->baz = 1; var_dump($y); --- NEWS | 2 + UPGRADING | 54 ++++++++++++------- Zend/tests/026.phpt | 2 +- Zend/tests/033.phpt | 4 +- Zend/tests/bug52041.phpt | 12 ++--- Zend/tests/bug52614.phpt | 2 +- Zend/zend_execute.c | 4 +- ext/dom/tests/bug47430.phpt | 4 +- ext/reflection/tests/bug40431.phpt | 4 +- tests/classes/implicit_instantiation_001.phpt | 18 +++---- 10 files changed, 60 insertions(+), 46 deletions(-) diff --git a/NEWS b/NEWS index 01c664b908..6f63542f97 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,8 @@ PHP NEWS - Changed array_combine() to return empty array instead of FALSE when both parameter arrays are empty. FR #34857. (joel.perras@gmail.com) - Changed third parameter of preg_match_all() to optional. FR #53238. (Adam) +- Changed silent casting of null/''/false into an Object when adding + a property into a warning. (Scott) - General improvements: . Added multibyte suppport by default. Previosly php had to be compiled diff --git a/UPGRADING b/UPGRADING index da3048cf71..8787b4018f 100755 --- a/UPGRADING +++ b/UPGRADING @@ -4,19 +4,19 @@ UPGRADE NOTES - PHP X.Y 1. Changes made to default configuration 2. Reserved words and classes -3. Changes made to existing functions -4. Changes made to existing methods -5. Changes made to existing classes -6. Deprecated -7. Removed -8. Extensions: +3. Changes made to engine behaviour +4. Changes made to existing functions +5. Changes made to existing methods +6. Changes made to existing classes +7. Deprecated +8. Removed +9. Extensions: a. moved out to PECL and actively maintained there b. no longer maintained c. with changed behaviour d. no longer possible to disable -9. Changes in SAPI support -10. Changes in INI directives -11. Syntax additions +10. Changes in SAPI support +11. Changes in INI directives 12. Syntax additions 13. Windows support 14. New in PHP X.Y: @@ -87,8 +87,22 @@ UPGRADE NOTES - PHP X.Y - +============================= +3. Changes made to engine behaviour +============================= + +- Turning null, false or empty string into an object by adding a property + will now emit a warning instead of an E_STRICT error. + + $test = null; + $test->baz = 1; + + To create a generic object you can use StdClass: + $test = new StdClass; + $text->baz = 1; + ===================================== -3. Changes made to existing functions +4. Changes made to existing functions ===================================== - array_combine now returns array() instead of FALSE when two empty arrays are @@ -150,23 +164,23 @@ UPGRADE NOTES - PHP X.Y =================================== -4. Changes made to existing methods +5. Changes made to existing methods =================================== - =================================== -5. Changes made to existing classes +6. Changes made to existing classes =================================== - ============= -6. Deprecated +7. Deprecated ============= ========== -7. Removed +8. Removed ========== a. removed features @@ -215,7 +229,7 @@ UPGRADE NOTES - PHP X.Y - continue $var; ============= -8. Extensions +9. Extensions ============= a. moved out to PECL and actively maintained there @@ -237,7 +251,7 @@ UPGRADE NOTES - PHP X.Y - ========================== -9. Changes in SAPI support +10. Changes in SAPI support ========================== - The REQUEST_TIME value inside server now returns a floating point number @@ -245,7 +259,7 @@ UPGRADE NOTES - PHP X.Y value should be returning float and not time_t. ============================= -10. Changes in INI directives +11. Changes in INI directives ============================= - Added session.upload_progress.enabled, session.upload_progress.cleanup, @@ -264,7 +278,7 @@ UPGRADE NOTES - PHP X.Y three times. ==================== -11. Syntax additions +12. Syntax additions ==================== - Array dereferencing. @@ -273,14 +287,14 @@ UPGRADE NOTES - PHP X.Y $foo->bar()[0] =================== -12. Windows support +13. Windows support =================== - is_link now works properly for symbolic links on Windows Vista or later. Earlier systems do not support symbolic links. =================== -13. New in PHP X.Y: +14. New in PHP X.Y: =================== a. New libraries diff --git a/Zend/tests/026.phpt b/Zend/tests/026.phpt index 784b12c69b..5fa0e1677c 100644 --- a/Zend/tests/026.phpt +++ b/Zend/tests/026.phpt @@ -21,5 +21,5 @@ print "ok\n"; Notice: Trying to get property of non-object in %s on line %d ok -Strict Standards: Creating default object from empty value in %s on line %d +Warning: Creating default object from empty value in %s on line %d ok diff --git a/Zend/tests/033.phpt b/Zend/tests/033.phpt index c8651159a6..17319e0d61 100644 --- a/Zend/tests/033.phpt +++ b/Zend/tests/033.phpt @@ -26,6 +26,6 @@ Notice: Undefined variable: arr in %s on line %d Notice: Trying to get property of non-object in %s on line %d -Strict Standards: Creating default object from empty value in %s on line %d +Warning: Creating default object from empty value in %s on line %d -Strict Standards: Creating default object from empty value in %s on line %d +Warning: Creating default object from empty value in %s on line %d diff --git a/Zend/tests/bug52041.phpt b/Zend/tests/bug52041.phpt index f2eb8d3ed8..944baf4edd 100644 --- a/Zend/tests/bug52041.phpt +++ b/Zend/tests/bug52041.phpt @@ -25,27 +25,27 @@ var_dump(foo()); --EXPECTF-- Notice: Undefined variable: x in %sbug52041.php on line 3 -Strict Standards: Creating default object from empty value in %sbug52041.php on line 6 +Warning: Creating default object from empty value in %sbug52041.php on line 6 Notice: Undefined variable: x in %sbug52041.php on line 3 -Strict Standards: Creating default object from empty value in %sbug52041.php on line 7 +Warning: Creating default object from empty value in %sbug52041.php on line 7 Notice: Undefined variable: x in %sbug52041.php on line 3 -Strict Standards: Creating default object from empty value in %sbug52041.php on line 8 +Warning: Creating default object from empty value in %sbug52041.php on line 8 Notice: Undefined variable: x in %sbug52041.php on line 3 -Strict Standards: Creating default object from empty value in %sbug52041.php on line 9 +Warning: Creating default object from empty value in %sbug52041.php on line 9 Notice: Undefined variable: x in %sbug52041.php on line 3 -Strict Standards: Creating default object from empty value in %sbug52041.php on line 10 +Warning: Creating default object from empty value in %sbug52041.php on line 10 Notice: Undefined variable: x in %sbug52041.php on line 3 -Strict Standards: Creating default object from empty value in %sbug52041.php on line 11 +Warning: Creating default object from empty value in %sbug52041.php on line 11 Notice: Undefined variable: x in %sbug52041.php on line 3 diff --git a/Zend/tests/bug52614.phpt b/Zend/tests/bug52614.phpt index 38a210b9a9..d220881679 100644 --- a/Zend/tests/bug52614.phpt +++ b/Zend/tests/bug52614.phpt @@ -72,7 +72,7 @@ array(0) { array(0) { } -Strict Standards: Creating default object from empty value in %sbug52614.php on line 52 +Warning: Creating default object from empty value in %sbug52614.php on line 52 NULL object(stdClass)#%d (1) { ["a"]=> diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 258a4ccd00..340ab29712 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -554,7 +554,7 @@ static inline void make_real_object(zval **object_ptr TSRMLS_DC) || (Z_TYPE_PP(object_ptr) == IS_BOOL && Z_LVAL_PP(object_ptr) == 0) || (Z_TYPE_PP(object_ptr) == IS_STRING && Z_STRLEN_PP(object_ptr) == 0) ) { - zend_error(E_STRICT, "Creating default object from empty value"); + zend_error(E_WARNING, "Creating default object from empty value"); SEPARATE_ZVAL_IF_NOT_REF(object_ptr); zval_dtor(*object_ptr); @@ -660,7 +660,7 @@ static inline void zend_assign_to_object(zval **retval, zval **object_ptr, zval zval_dtor(*object_ptr); object_init(*object_ptr); object = *object_ptr; - zend_error(E_STRICT, "Creating default object from empty value"); + zend_error(E_WARNING, "Creating default object from empty value"); } else { zend_error(E_WARNING, "Attempt to assign property of non-object"); if (retval) { diff --git a/ext/dom/tests/bug47430.phpt b/ext/dom/tests/bug47430.phpt index d3ca435e5f..243fe8441c 100644 --- a/ext/dom/tests/bug47430.phpt +++ b/ext/dom/tests/bug47430.phpt @@ -21,9 +21,9 @@ print_r($arr); ?> --EXPECTF-- -Strict Standards: Creating default object from empty value in %s on line %d +Warning: Creating default object from empty value in %s on line %d -Strict Standards: Creating default object from empty value in %s on line %d +Warning: Creating default object from empty value in %s on line %d Array ( [0] => Value diff --git a/ext/reflection/tests/bug40431.phpt b/ext/reflection/tests/bug40431.phpt index 6e6e4c5eb1..863df7a78f 100644 --- a/ext/reflection/tests/bug40431.phpt +++ b/ext/reflection/tests/bug40431.phpt @@ -4,7 +4,7 @@ Bug #40431 (dynamic properties may cause crash in ReflectionProperty methods) value = 'value'; $RefObj = new ReflectionObject($Obj); @@ -78,8 +78,6 @@ echo "Done\n"; ?> --EXPECTF-- === 1st test === - -Strict Standards: Creating default object from empty value in %s on line %d array(1) { [0]=> &object(ReflectionProperty)#%d (2) { diff --git a/tests/classes/implicit_instantiation_001.phpt b/tests/classes/implicit_instantiation_001.phpt index 460cdc97f2..8d2f32da21 100644 --- a/tests/classes/implicit_instantiation_001.phpt +++ b/tests/classes/implicit_instantiation_001.phpt @@ -39,43 +39,43 @@ var_dump($c); ---( $c->boolFalse )--- --> Attempting implicit conversion to object using increment... -Strict Standards: Creating default object from empty value in %s on line 18 +Warning: Creating default object from empty value in %s on line 18 --> Attempting implicit conversion to object using assignment... -Strict Standards: Creating default object from empty value in %s on line 22 +Warning: Creating default object from empty value in %s on line 22 --> Attempting implicit conversion to object using combined assignment... -Strict Standards: Creating default object from empty value in %s on line 26 +Warning: Creating default object from empty value in %s on line 26 ---( $c->emptyString )--- --> Attempting implicit conversion to object using increment... -Strict Standards: Creating default object from empty value in %s on line 18 +Warning: Creating default object from empty value in %s on line 18 --> Attempting implicit conversion to object using assignment... -Strict Standards: Creating default object from empty value in %s on line 22 +Warning: Creating default object from empty value in %s on line 22 --> Attempting implicit conversion to object using combined assignment... -Strict Standards: Creating default object from empty value in %s on line 26 +Warning: Creating default object from empty value in %s on line 26 ---( $c->null )--- --> Attempting implicit conversion to object using increment... -Strict Standards: Creating default object from empty value in %s on line 18 +Warning: Creating default object from empty value in %s on line 18 --> Attempting implicit conversion to object using assignment... -Strict Standards: Creating default object from empty value in %s on line 22 +Warning: Creating default object from empty value in %s on line 22 --> Attempting implicit conversion to object using combined assignment... -Strict Standards: Creating default object from empty value in %s on line 26 +Warning: Creating default object from empty value in %s on line 26 ---( $c->boolTrue )--- -- 2.40.0