ID: 44677 User updated by: kudung at gmx dot net Reported By: kudung at gmx dot net Status: Bogus Bug Type: Class/Object related Operating System: Debian 4 PHP Version: 5.2.5 New Comment:
so therefore it is not possible to pass an param of type object into an function, without cloning it to be sure that the original object is not changed in any way? but why does a param of type array get copied and can be altered without changing the original array? this might be an improvement, but if its against any rule of oop so just throw this thougt away. Previous Comments: ------------------------------------------------------------------------ [2008-04-09 11:25:33] [EMAIL PROTECTED] RTFM: http://www.php.net/manual/en/language.oop5.basic.php "When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object that was assigned. This behaviour is the same when passing instances to a function. A copy of an already created object can be made by cloning it." ------------------------------------------------------------------------ [2008-04-09 10:01:55] kudung at gmx dot net Description: ------------ Hi, just discovered that an parameter wich passed to an function as an non reference of type object is handeld as an reference, but if i pass a parameter of type array to the function it is handled as a copie as it should be. Reproduce code: --------------- class foob { function testbar( $das ) { unset( $das->ding ); } } function testbar( $das ) { unset( $das->ding ); } $ers = new stdClass(); $ers->ding = '323'; testbar($ers); var_dump( $ers ); $ers2 = new stdClass(); $ers2->ding = '323'; $foob = new foob(); $foob->testbar($ers2); var_dump( $ers2 ); Expected result: ---------------- Expected that properties still exists: object(stdClass)#1 (1) { ["ding"]=> string(3) "323" } object(stdClass)#2 (1) { ["ding"]=> string(3) "323" } Actual result: -------------- Output: object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44677&edit=1