Bug #74289 [Opn]: Strange behavior when casting the types of functions/methods

From: Date: Sat, 25 Mar 2017 11:43:43 +0000
Subject: Bug #74289 [Opn]: Strange behavior when casting the types of functions/methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208067@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74289&edit=1 ID: 74289 Updated by: cmb@php.net Reported by: erickskrauch at yandex dot ru Summary: Strange behavior when casting the types of functions/methods Status: Open Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 7.1.3 Block user comment: N Private report: N New Comment: Simplified reproducer: <https://3v4l.org/UeRYn>. Argument type declarations exhibit the same behavior: <https://3v4l.org/ROpEJ>. The documentation states[1], however: > By default, PHP will coerce values of the wrong type into the > expected scalar type if possible. At least this would need clarification wrt. objects implementing ::__toString(). [1] <http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration> Previous Comments: ------------------------------------------------------------------------ [2017-03-22 11:14:29] erickskrauch at yandex dot ru Description: ------------ I'm not sure if this is a bug, but when I was developing a wrapper for xml document, I ran into strange behavior when casting types in the return value of the method. I expect that the asInt() method will work just like the directConversion(), but they work differently. Test script: --------------- https://3v4l.org/JnFCh Expected result: ---------------- string(3) "123" int(123) int(123) int(123) Actual result: -------------- string(3) "123" int(123) int(123) Fatal error: Uncaught TypeError: Return value of Parser::asInt() must be of the type integer, object returned in /in/JnFCh:22 Stack trace: #0 /in/JnFCh(44): Parser->asInt() #1 {main} thrown in /in/JnFCh on line 22 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74289&edit=1

« previous php.bugs (#208067) next »