|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-04-27 08:39 UTC] johannes@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 04:00:02 2025 UTC |
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