php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67829 php doesn't compute argument of function/method/constructor that doesn't exist
Submitted: 2014-08-12 14:17 UTC Modified: 2017-01-28 17:56 UTC
Votes:3
Avg. Score:3.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: an0nym at narod dot ru Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.0RC3 OS: *nix
Private report: No CVE-ID: None
 [2014-08-12 14:17 UTC] an0nym at narod dot ru
Description:
------------
Let's assume we have a function/method with side effects. Its result is used as argument of another function/method. If this another function/method does not exist (this may not lead to Fatal btw), the first function/method with side effect will not be executed as arguments of another function/method will not be computed. 

Possible cases:
- calling non-existent function/method with argument being the result of function/method with side effects - leads to fatal without expected side effects;
- creating new instance of a class with no constructor (!= with empty constructor) passing it the result of function/method with side effects - leads to normal execution without expected side effects. 

Is this laziness intentional? It's strange to see this kind of laziness in language with functions/methods with possible side effects. 

If you consider this bug duplicate to https://bugs.php.net/bug.php?id=54162, please, explain the rationale behind introducing this kind of laziness in dynamically-typed language where non-pure functions with side-effects exist and caller most likely might not know whether callee has constructor or not. Links given there are quite general to get this specific information. Thank you in advance.

Test script:
---------------
<?php
class A {}

class B
{
    public function __construct() {}
}

class D
{
    protected function test1($class_name)
    {
        echo $class_name, "\n";
        return 'BLAH';
    }

    public function test($class_name)
    {
        return new $class_name($this->test1($class_name));
    }
}

$D = new D;
$D->test('A');
$D->test('B');
$D->test('C');

Expected result:
----------------
A
B
C

Fatal error: Class 'C' not found in test.php on line 19


Actual result:
--------------
B

Fatal error: Class 'C' not found in test.php on line 19


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-18 22:51 UTC] stas@php.net
This is the intended behavior of the new operator in PHP, changing it would require an RFC and can not happen in 5.6 due to BC break following from that. If you are interested in changing it, please submit an RFC.
 [2014-11-18 22:52 UTC] stas@php.net
-Type: Bug +Type: Feature/Change Request
 [2016-03-27 20:23 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-03-27 20:23 UTC] nikic@php.net
The issue with new argument evaluation has been fixed in PHP 7.1.
 [2017-01-28 17:56 UTC] cmb@php.net
> The issue with new argument evaluation has been fixed in PHP 7.1.

Apparently, this info is missing in UPGRADING.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Jan 22 21:03:35 2022 UTC