Bug #53053 [Opn->Fbk]: Magic Method __set changes object class

From: Date: Thu, 14 Oct 2010 02:43:28 +0000
Subject: Bug #53053 [Opn->Fbk]: Magic Method __set changes object class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155159@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53053&edit=1

 ID:                 53053
 Updated by:         aharvey@php.net
 Reported by:        dave dot a dot roberts at gmail dot com
 Summary:            Magic Method __set changes object class
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            Class/Object related
 Operating System:   FreeBSD 8.1-RELEASE
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

Please provide a complete reproduction script, preferably (well) under
50 lines of code.

For the record, I can't reproduce this with the following script:

<?php
class C {
    public function __set($name, $value) {
        $this->$name = $value;
    }
}

$c = new C;
var_dump(get_class($c));
$c->foo = 'bar';
var_dump(get_class($c));
?>


Previous Comments:
------------------------------------------------------------------------
[2010-10-13 17:49:42] dave dot a dot roberts at gmail dot com

Description:
------------
I have an object I created from class Post.

$p = new Post();

get_class($p) will return the class Post.

After I assign a variable to the class using the magic method __set

$p->datereceived = "1234";

get_class($p) will return stdClass.

Test script:
---------------
$p = new Post();
print(get_class($p)); // returns Post
$p->datereceived = "1234";
print(get_class($p)); // returns stdClass.

Expected result:
----------------
The classname of Post should be returned twice.

Actual result:
--------------
Post is returned the first time, stdClass is returned the second time.


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



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


Thread (3 messages)

« previous php.bugs (#155159) next »