php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74476 Cast and TypeHint do not have the expected behavior
Submitted: 2017-04-19 20:02 UTC Modified: 2017-04-19 21:28 UTC
From: tonin at bolzan dot io Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.1.4 OS: All
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tonin at bolzan dot io
New email:
PHP Version: OS:

 

 [2017-04-19 20:02 UTC] tonin at bolzan dot io
Description:
------------
Cast and TypeHint do not have the expected behavior
(function () : object { return (object) []; })();
must be an instance of object, instance of stdClass returned

Test script:
---------------
php -a
php > (function () : object { return (object) []; })();
PHP Warning:  Uncaught TypeError: Return value of {closure}() must be an instance of object, instance of stdClass returned in php shell code:1
Stack trace:
#0 php shell code(1): {closure}()
#1 {main}
  thrown in php shell code on line 1

Expected result:
----------------
Work normal

Actual result:
--------------
PHP Warning:  Uncaught TypeError: Return value of {closure}() must be an instance of object, instance of stdClass returned in php shell code:1
Stack trace:
#0 php shell code(1): {closure}()
#1 {main}
  thrown in php shell code on line 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-19 21:28 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2017-04-19 21:28 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Note that there is an RFC[1] under dicussion which suggests to
introduce `object` type declarations.

[1] <https://wiki.php.net/rfc/object-typehint>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 01:01:33 2025 UTC