Req #76887 [Opn->Dup]: New Useful Magic Methods

From: Date: Sat, 15 Sep 2018 21:34:17 +0000
Subject: Req #76887 [Opn->Dup]: New Useful Magic Methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217071@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76887&edit=1 ID: 76887 Updated by: requinix@php.net Reported by: klaussantana at gmail dot com Summary: New Useful Magic Methods -Status: Open +Status: Duplicate Type: Feature/Change Request -Package: Reflection related +Package: Class/Object related Operating System: Any PHP Version: Irrelevant Block user comment: N Private report: N New Comment: This is something that needs to be discussed on the internals list. Previous Comments: ------------------------------------------------------------------------ [2018-09-15 21:26:39] klaussantana at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=76887&edit=1

« previous php.bugs (#217071) next »