Req #76887 [NEW]: New Useful Magic Methods
| From: | klaussantana at gmail dot com | Date: | Sat, 15 Sep 2018 21:26:39 +0000 |
| Subject: | Req #76887 [NEW]: New Useful Magic Methods | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-217070@lists.php.net to get a copy of this message | ||
From: klaussantana at gmail dot com
Operating system: Any
PHP version: Irrelevant
Package: Reflection related
Bug Type: Feature/Change Request
Bug description:New Useful Magic Methods
Description:
------------
I'm sugesting some new magic methods for objects that'll add some useful
behaviours to objects in new versions of PHP.
1. __toNumber()
Do some calculations on the object and return a number automatically
when an object is casted as a number, be it integer or float. Useful to
AI scripts for calculating the numerical weight of an object and many
other stuff. Can be achieved by using "(float) ( (string) $Object )",
but this costs a lot of characters in every expression and misuses the
"__toString" method.
2. __toArray()
Must create and return a raw array with keys being the names of the
properties of the working object and with their respective values being
references to their counterparts in the working object. Pretty much do
the same things achieved by "ArrayIterator::getArrayCopy()", but
slightly different. Automatically called when the object is casted as an
array (eg.: "(array) $Object").
This method scope could detect it's parent's in a way that it can return
the properties acordingly with the scope that called the method. For
example, if in an outer scope it will only return the public properties,
if from an inner scope it will return protected or private properties as
well.
--
Edit bug report at https://bugs.php.net/bug.php?id=76887&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76887&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76887&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76887&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76887&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76887&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76887&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76887&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76887&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76887&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76887&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76887&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76887&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76887&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76887&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76887&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76887&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76887&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76887&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76887&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76887&r=mysqlcfg