Bug #67829 [NEW]: php doesn't compute argument of function/method/constructor that doesn't exist
| From: | an0nym at narod dot ru | Date: | Tue, 12 Aug 2014 14:17:04 +0000 |
| Subject: | Bug #67829 [NEW]: php doesn't compute argument of function/method/constructor that doesn't exist | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187092@lists.php.net to get a copy of this message | ||
From: an0nym at narod dot ru
Operating system: *nix
PHP version: 5.6.0RC3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:php doesn't compute argument of function/method/constructor that doesn't
exist
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 bug report at https://bugs.php.net/bug.php?id=67829&edit=1
--