php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45689 Additional magic methods
Submitted: 2008-08-02 14:40 UTC Modified: 2008-08-02 15:09 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: joe at calledtoconstruct dot net Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.3.0alpha1 OS: n/a
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-08-02 14:40 UTC] joe at calledtoconstruct dot net
Description:
------------
In addition to the existing __call, __set, __get, etc...  it would be Very nice to have:

__add : for code that uses the + and += operators
__subtract : for code that uses the - and -= operators
__multiply : * and *=
__divide : / and /=

and

__concat (or __concatinate) for . and .= operators


Expected result:
----------------
So that we can now write:

$objFoo = new Foo();
$objBar = new Bar();

A)  $objFoo += $objBar;
or
B)  $objFoo += "fooBar";
or
C)  $objFoobar = $objFoo + $objBar;

which would be equivellent to writing:

A:  $objFoo = $objFoo->__add($objBar);
B:  $objFoo = $objFoo->__add("fooBar");
C:  $objFoobar = $objFoo->__add($objBar);

In my specific case (the task I'm trying to accomplish, which brought about this idea), I'm doing:

$objFoo->value .= "something";

which, I imagine, would perform:

$tempOne = $objFoo->__get("value");
$tempTwo = $tempOne->__concat("something");
$objFoo->__set("value", $tempTwo);

because $tempOne might be an object.

Actual result:
--------------
PHP is Awesome!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-02 15:09 UTC] derick@php.net
We will not implement operator overloading in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 16:01:29 2024 UTC