|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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: Sat Jan 22 14:03:39 2022 UTC