Req #44282 [Opn->Csd]: new function get_object_name()
| From: | reeze@php.net | Date: | Fri, 22 Mar 2013 15:37:37 +0000 |
| Subject: | Req #44282 [Opn->Csd]: new function get_object_name() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-178009@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=44282&edit=1
ID: 44282
Updated by: reeze@php.net
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