]> granicus.if.org Git - php/commitdiff
Silently casting an empty string, null or false into an object by adding a property
authorScott MacVicar <scottmac@php.net>
Fri, 31 Dec 2010 16:57:45 +0000 (16:57 +0000)
committerScott MacVicar <scottmac@php.net>
Fri, 31 Dec 2010 16:57:45 +0000 (16:57 +0000)
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.

<?php
$x = '';
// $x = null;
// $x = false;
$x->baz = 1;
var_dump($x);

$y = 1;
$y->baz = 1;
var_dump($y);

NEWS
UPGRADING
Zend/tests/026.phpt
Zend/tests/033.phpt
Zend/tests/bug52041.phpt
Zend/tests/bug52614.phpt
Zend/zend_execute.c
ext/dom/tests/bug47430.phpt
ext/reflection/tests/bug40431.phpt
tests/classes/implicit_instantiation_001.phpt

diff --git a/NEWS b/NEWS
index 01c664b908a33cec8d520729cab3d175191e8bb8..6f63542f9767bdcb578e861940218162ff2a430d 100644 (file)
--- 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
index da3048cf713131454332f6153ea3b512c926a3ce..8787b4018fdbca92807e2c660397faaf65d7d1cc 100755 (executable)
--- 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
index 784b12c69ba8bc45005d4d65fd8811a33f67e1b9..5fa0e1677cae7e6c1e147a0b433a4e271e70cffa 100644 (file)
@@ -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
index c8651159a66527d1ee178fb34ab4bef2e42d10b1..17319e0d6105c38799d10f772c80e3de9367c061 100644 (file)
@@ -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
index f2eb8d3ed893cc8e5823f26b21536da35ebde949..944baf4eddfec47241517060a2d4c4bc62a0683e 100644 (file)
@@ -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
 
index 38a210b9a9d53502d885ba1ca4e043b8ddecece1..d220881679ec3231db7c1b8a92902c727d72d8fa 100644 (file)
@@ -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"]=>
index 258a4ccd000e88c0d5d10c81a6418d8e5ec79d10..340ab297124f8ceaad9f900f28d6e950f19976a0 100644 (file)
@@ -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) {
index d3ca435e5f0a5642d1c0ad1b2bb1ad153304fedc..243fe8441cca0d8b8589dd443e88427618bbe1f7 100644 (file)
@@ -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
index 6e6e4c5eb16bc1724f13cae07f3d480bd88958b5..863df7a78fef2b711699b88fa180f1556c8af785 100644 (file)
@@ -4,7 +4,7 @@ Bug #40431 (dynamic properties may cause crash in ReflectionProperty methods)
 <?php
 
 echo "=== 1st test ===\n";
-
+$Obj = new stdClass;
 $Obj->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) {
index 460cdc97f25b454305dc9d78a167e39b0de31284..8d2f32da21bac37204529f22d01dfe623a0978eb 100644 (file)
@@ -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 )---