php.net |  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
 [2010-10-13 17:49 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-14 04:43 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2010-10-14 04:43 UTC] aharvey@php.net
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));
?>
 [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: Sun May 19 12:01:30 2024 UTC