Req #67829 [Csd]: php doesn't compute argument of function/method/constructor that doesn't exist
| From: | cmb@php.net | Date: | Sat, 28 Jan 2017 17:56:16 +0000 |
| Subject: | Req #67829 [Csd]: php doesn't compute argument of function/method/constructor that doesn't exist | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206992@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67829&edit=1
ID: 67829
Updated by: cmb@php.net
Reported by: an0nym at narod dot ru
Summary: php doesn't compute argument of
function/method/constructor that doesn't exist
Status: Closed
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *nix
PHP Version: 5.6.0RC3
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
> The issue with new argument evaluation has been fixed in PHP 7.1.
Apparently, this info is missing in UPGRADING.
Previous Comments:
------------------------------------------------------------------------
[2016-03-27 20:23:39] nikic@php.net
The issue with new argument evaluation has been fixed in PHP 7.1.
------------------------------------------------------------------------
[2015-10-12 20:44:55] requinix@php.net
Related To: Bug #70698
------------------------------------------------------------------------
[2014-11-18 22:51:36] 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-08-12 14:17:04] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67829&edit=1