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

 ID:                 52484
 User updated by:    bastard dot internets at gmail dot com
 Reported by:        bastard dot internets at gmail dot com
 Summary:            __set() ignores setting properties with empty names
 Status:             Open
 Type:               Bug
 Package:            Class/Object related
 Operating System:   WIN
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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