Edit report at https://bugs.php.net/bug.php?id=44282&edit=1

 ID:                 44282
 Updated by:         [email protected]
 Reported by:        msaspence at gmail dot com
 Summary:            new function get_object_name()
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 PHP Version:        5.2.5
-Assigned To:        
+Assigned To:        reeze
 Block user comment: N
 Private report:     N

 New Comment:

I thought __toString() magic method is what you want. close for now


Previous Comments:
------------------------------------------------------------------------
[2008-02-28 10:55:36] msaspence at gmail dot com

Description:
------------
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:
---------------
Currently

<?php

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');
$$object->printName();

?> 

Expected result:
----------------
How it might be done:
<?php

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

}

$object = 'myObject';
$$object = new myClass;
$$object->printName();

?> 



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



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

Reply via email to