|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74289 Strange behavior when casting the types of functions/methods
Submitted: 2017-03-22 11:14 UTC Modified: 2021-09-01 14:48 UTC
From: erickskrauch at yandex dot ru Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.1.3 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: erickskrauch at yandex dot ru
New email:
PHP Version: OS:


 [2017-03-22 11:14 UTC] erickskrauch at yandex dot ru
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:

Expected result:
string(3) "123"

Actual result:
string(3) "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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-25 11:43 UTC]
Simplified reproducer: <>. Argument type
declarations exhibit the same behavior: <>.

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
 [2021-09-01 14:48 UTC]
-Type: Bug +Type: Documentation Problem
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 06:01:30 2024 UTC