From: generalpd at gmx dot de
Operating system: all
PHP version: 5.3.0
PHP Bug Type: Feature/Change Request
Bug description: __operator() magic method
Description:
------------
My suggestion is a new magic method called __operator($op, $rightValue) or
(if that might be the better way) __operator($leftValue, $op)
If defined, a class should be able to handle an operation, like "$classA +
$classOrValueB". What the method returns is the result of that of that
operation.
Reproduce code:
---------------
// first way
class A1
{
// the method of the instance of $a1
public function __operator($operator, $rightValue)
{
var_dump($rightValue); // 'Hi, All!'
var_dump($operator); // '.'
return '666 . ' . $rightValue;
}
}
// second way
class A2
{
// the method of the instance of $a2
public function __operator($leftValue, $operator)
{
var_dump($leftValue); // 'Hello, World!'
var_dump($operator); // '+'
return '777 + ' . $leftValue;
}
}
// 1st way
$a1 = new A1();
$c1 = $a1 . 'Hi, All!'; // '666 . Hi, All!'
// the result of __operator() method
// 2nd way
$a2 = new A2();
$c2 = 'Hello, World!' + $a2; // '777 + Hello, World!'
// the result of __operator() method
Expected result:
----------------
$c1 = '666 . Hi, All!';
$c2 = '777 + Hello, World!';
Actual result:
--------------
-----
--
Edit bug report at http://bugs.php.net/?id=49691&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49691&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49691&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49691&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49691&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49691&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49691&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49691&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49691&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49691&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49691&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49691&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49691&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49691&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49691&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49691&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49691&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49691&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49691&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49691&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49691&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49691&r=mysqlcfg