Edit report at http://bugs.php.net/bug.php?id=52484&edit=1

 ID:                 52484
 Updated by:         fel...@php.net
 Reported by:        bastard dot internets at gmail dot com
 Summary:            __set() ignores setting properties with empty names
-Status:             Open
+Status:             Closed
 Type:               Bug
-Package:            Class/Object related
+Package:            Scripting Engine problem
-Operating System:   WIN
+Operating System:   Irrelevant
 PHP Version:        5.3.3
-Assigned To:        
+Assigned To:        felipe
 Block user comment: N

 New Comment:

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2010-08-01 15:27:03] fel...@php.net

Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=301755
Log: - Fixed bug #52484 (__set() ignores setting properties with empty
names)

------------------------------------------------------------------------
[2010-07-30 06:51:58] bastard dot internets at gmail dot com

To clarify my second paragraph in the description, only by removing
__set() from the class will the desired error correctly generate.  IE,
in any method, "$p = null; $this->$p = true;" will cause an expected
error, just not if the __set() method exists.

------------------------------------------------------------------------
[2010-07-29 11:29:02] bastard dot internets at gmail dot com

Er, actual result:



SET  = 2

A Object

(

)

------------------------------------------------------------------------
[2010-07-29 11:24:59] bastard dot internets at gmail dot com

Description:
------------
Within only __set(), you can set a value of a new property with an empty
name ($p = null; $this->$p = 1;).  The property won't really be created
though - the effects will be invisible to the user.  No errors,
warnings, or notices are generated.  This lack of an error message might
cause difficult to pinpoint bugs since all assignments of previously
undeclared properties within object scope regardless of originating
method are routed through __set();



Elsewhere in the object, attempting this will cause a fatal 'Cannot
access empty property' error as expected.

Test script:
---------------
<?php



class A{



        function __set($prop, $val) {

                echo "SET $prop = $val\n";

                $this->$prop = $val; // should've caused error

                }



        }



$a = new A();

$prop = null;



$a->$prop = 2;



print_r($a); // empty object



?>

Expected result:
----------------
fatal 'Cannot set empty property' or 'invalid property name' error.

Actual result:
--------------
Nothing.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52484&edit=1

Reply via email to