|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53053 Magic Method __set changes object class
Submitted: 2010-10-13 17:49 UTC Modified: 2010-10-15 15:30 UTC
From: dave dot a dot roberts at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.3.3 OS: FreeBSD 8.1-RELEASE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
24 + 28 = ?
Subscribe to this entry?

 [2010-10-13 17:49 UTC] dave dot a dot roberts at gmail dot com
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-14 04:43 UTC]
-Status: Open +Status: Feedback
 [2010-10-14 04:43 UTC]
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:

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

$c = new C;
$c->foo = 'bar';
 [2010-10-15 15:30 UTC] dave dot a dot roberts at gmail dot com
-Status: Feedback +Status: Closed
 [2010-10-15 15:30 UTC] dave dot a dot roberts at gmail dot com
I think this was happening because I was trying to pull an object out of an array by the wrong key.  Sorry to waste your time.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 19:01:30 2024 UTC