php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78239 Deprecation notice during string conversion converted to exception hangs
Submitted: 2019-07-02 10:06 UTC Modified: 2019-07-03 08:57 UTC
From: cxlblm at gmail dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 7.4.0alpha2 OS: Linux 788f0b0a7ad1 4.9.125-linux
Private report: No CVE-ID: None
 [2019-07-02 10:06 UTC] cxlblm at gmail dot com
Description:
------------
Deprecated: Function ReflectionType::__toString() is deprecated  with set_error_handler blocked

Test script:
---------------
<?php

function handleError($level, $message, $file = '', $line = 0, $context = [])
{
    throw new ErrorException($message, 0, $level, $file, $line);
}

set_error_handler('handleError');

class A
{
    
    public function abc(): bool
    {
        return false;
    }
}

$r = new ReflectionMethod("A", "abc");
(string)$r->getReturnType();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-02 10:14 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2019-07-02 10:14 UTC] nikic@php.net
What is the bug? I get:

Fatal error: Uncaught ErrorException: Function ReflectionType::__toString() is deprecated in /home/nikic/php-7.4/t077.php:20
Stack trace:
#0 /home/nikic/php-7.4/t077.php(20): handleError(8192, 'Function Reflec...', '/home/nikic/php...', 20, Array)
#1 {main}
  thrown in /home/nikic/php-7.4/t077.php on line 20

Which looks correct to me.
 [2019-07-02 10:21 UTC] cxlblm at gmail dot com
-Status: Feedback +Status: Open
 [2019-07-02 10:21 UTC] cxlblm at gmail dot com
I'm sorry! I lost some code
(string)$r->getReturnType() ?: "";
 [2019-07-02 10:26 UTC] cmb@php.net
Last line should be

  $r->getReturnType()->getName();
 [2019-07-02 13:17 UTC] cxlblm at gmail dot com
Sorry, My english is terrible. Above code will worked with Exception, but now blocked!
 [2019-07-03 07:54 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2019-07-03 07:54 UTC] cmb@php.net
As of PHP 7.4.0, ReflectionType::__toString() generates a
deprecation notice[1], which is caught by your error handler.
This is expected behavior.

If you do not get a similar output as posted by nikic@php.net,
please re-open this ticket, and post the output you have got.

Thanks.

[1] <https://github.com/php/php-src/blob/6ab04a6eef0750ea2d4365be7f9bcfd9caa33449/UPGRADING#L345-L349>
 [2019-07-03 08:13 UTC] cxlblm at gmail dot com
Please see this url: https://3v4l.org/7UK9C
error: Process exited with code 137.
 [2019-07-03 08:35 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Assigned To: cmb +Assigned To:
 [2019-07-03 08:35 UTC] cmb@php.net
Thanks!  This is indeed unexpected.  I cannot reproduce, though.
 [2019-07-03 08:42 UTC] nikic@php.net
-Status: Re-Opened +Status: Verified
 [2019-07-03 08:42 UTC] nikic@php.net
Confirming hang with the ?: "" at the end.
 [2019-07-03 08:57 UTC] nikic@php.net
-Summary: set_error_handler() blocked +Summary: Deprecation notice during string conversion converted to exception hangs
 [2019-07-03 09:00 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2bf880db2c624a32f130e0da309b22dcf782609d
Log: Fixed bug #78239
 [2019-07-03 09:00 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC