|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44282 new function get_object_name()
Submitted: 2008-02-28 10:55 UTC Modified: 2013-03-22 15:37 UTC
Avg. Score:3.8 ± 1.3
Reproduced:6 of 7 (85.7%)
Same Version:5 (83.3%)
Same OS:3 (50.0%)
From: msaspence at gmail dot com Assigned: reeze (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: msaspence at gmail dot com
New email:
PHP Version: OS:


 [2008-02-28 10:55 UTC] msaspence at gmail dot com
Currently to get the objects variable name within the object you must pass it as a parameter and have the constructor define it.

This solution while simple would be tidier if there was a function that could retrieve the object's variable instance from inside itself.

Reproduce code:


class myClass {
    function __construct($objectName) {
        $this->objectName = $objectName;
    function printName() {
        echo "the name of this object instance is ".$this->objectName;


$object = 'myObject';
$$object = new myClass('$object');


Expected result:
How it might be done:

class myClass {
    function printName() {
        echo "the name of this object instance is ".$this->get_object_name();


$object = 'myObject';
$$object = new myClass;



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-22 15:37 UTC]
I thought __toString() magic method is what you want. close for now
 [2013-03-22 15:37 UTC]
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: reeze
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jan 18 05:07:33 2022 UTC