|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-05-07 12:59 UTC] dbforch at hotmail dot com
[2020-12-23 17:16 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Package: Feature/Change Request
+Package: Scripting Engine problem
-Assigned To:
+Assigned To: cmb
[2020-12-23 17:16 UTC] cmb@php.net
[2020-12-23 17:16 UTC] cmb@php.net
-Status: Feedback
+Status: Suspended
-Assigned To: cmb
+Assigned To:
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
Description: ------------ In the current implementation it's impossible to convert an object to a number. I should exist a magic method called "__valueOf" which must return a float/int. In the case this magic method isn't declared , it should be returned a not zero value when converting to number (it happens, but generates the E_NOTICE anyway). Reproduce code: --------------- class Number{ private $value; public function __construct($n){ $this->value = +$n; } public function __toString(){ return (string)$this->value; } public function __valueOf(){ return $this->value; } } $n = new Number(2); echo $n . ':' . +$n; Expected result: ---------------- 2:2 Actual result: -------------- Notice: Object of class Number could not be converted to int in C:\test.php on line 16 2:1