-
Couldn't load subscription status.
- Fork 826
Open
Labels
bugDocumentation contains incorrect informationDocumentation contains incorrect information
Description
https://www.php.net/manual/en/function.is-callable.php says
is_callable()reports constructors as not being callable.
This is not true. At least not when called from a context where the constructor is callable, e.g. a child class constructor.
<?php
class ParentWithConstructor
{
public function __construct()
{
?>
ParentWithConstructor::__construct() was called<br/>
<?php
}
}
class ParentWithoutConstructor
{
}
class ChildOfParentWithConstructor extends ParentWithConstructor
{
public function __construct()
{
$isCallable = \is_callable([parent::class, '__construct']);
?>
<?=static::class?>::__construct() was called<br/>
$isCallable = <?=$isCallable?><br />
<?php
if ($isCallable) {
parent::__construct();
}
}
}
class ChildOfParentWithoutConstructor extends ParentWithoutConstructor
{
public function __construct()
{
$isCallable = \is_callable([parent::class, '__construct']);
?>
<?=static::class?>::__construct() was called<br/>
$isCallable = <?=$isCallable?><br />
<?php
if ($isCallable) {
parent::__construct();
}
}
}
?>
<p>
<?php
new ChildOfParentWithConstructor();
?>
</p>
<p>
<?php
new ChildOfParentWithoutConstructor();
?>
</p>
<p>
PHP version <?=PHP_VERSION?>
</p>The output was
ChildOfParentWithConstructor::__construct() was called
$isCallable = 1
ParentWithConstructor::__construct() was calledChildOfParentWithoutConstructor::__construct() was called
$isCallable =PHP version 7.3.11
This needs to be clarified, rather than having a blanket statement saying it does not work, when in fact it does in the right situations.
Metadata
Metadata
Assignees
Labels
bugDocumentation contains incorrect informationDocumentation contains incorrect information