ID:               48076
 Updated by:       [email protected]
 Reported By:      av3ng3r at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Doesn't matter
 PHP Version:      5.3.0RC1
 New Comment:

This has been discussed and rejected multiple times as we'd have some
conflicts. For instace should $a = new $object(); $b = array(); $b[$a] =
1; call toString or toNumber?

Please see other bug reports on this and internals archives for more
reasons.


Previous Comments:
------------------------------------------------------------------------

[2009-04-25 14:21:48] av3ng3r at gmail dot com

Description:
------------
Add the magic method __toNumber.

Reproduce code:
---------------
class Number
{
   private $number;
 
   //some useful example methods
   function isBetween($a, $b) { //is number between ? }
   //etc

   function __toNumber()
   {
     return $this->number;
   }
}

Expected result:
----------------
$c = new Number(3);

echo $c; //outputs: 3
var_dump($c->isBetween(2, 4)) //returns true

//cast it too a Price object (extended from Number)
$price = (Price) $c;

//override __toNumber()
echo $c; //outputs 3.00 for example



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=48076&edit=1

Reply via email to