Edit report at https://bugs.php.net/bug.php?id=74289&edit=1
ID: 74289
Updated by: [email protected]
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.