You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is_callable() reports constructors as not being callable.
And the code verify callability the __construct() through static callable-expression:
<?phpclassFoo
{
publicfunction__construct() {}
publicfunctionfoo() {}
}
var_dump(
is_callable(['Foo', '__construct']), // The static callable expression, as first entry is not object contextis_callable(['Foo', 'foo'])
);
At the same time, the __construct() is callable actually:
The example is probably trying to say that you cannot use is_callable(["Foo", "__construct"]) as a way of knowing if the class can be created with new.
if (is_callable(["Foo", "__construct"])) { // always false$object = newFoo(); // will never happen
}
(instead, to know if a class can be constructed, you need to use reflection)
Maybe the example is trying to say that despite the fact that the value that the function returns in the in-out parameter callable_name when specifying the arguments $syntax_only = true and $callable_name, although it looks like indicating the availability of the method for static invocation, it does not actually allow the method to be called statically?
And the example should just be supplemented, for example, like this:
<?phpclassFoo
{
publicfunction__construct() {}
publicfunctionfoo() {}
}
var_dump(
// Verify, if the '__construct' might be a callableis_callable(['Foo', '__construct'], true, $callable_name), // true// Get the __construct() callable name$callable_name, // Returns "Foo::__construct", that looks like callable static method// Verify, if the '__construct' is available as callable static methodis_callable(['Foo', '__construct']), // false// The same with the foo() non-static methodis_callable(['Foo', 'foo'], true, $callable_name), // true$callable_name, // Foo::foois_callable(['Foo', 'foo']), // Return false with static callable expression// Opposite the static callable expression, the non-static methods are callablesis_callable([newFoo(), '__construct']), // trueis_callable([newFoo(), 'foo']), // true
);
If this is the purpose of the second example, then the title of the example should be changed to something like: is_callable() with $syntax_only example.
Anyway, the example should be changed so that it becomes clear and specific, and directly says "why" it appeared on the page ;)
The page say:
And the code verify callability the __construct() through static callable-expression:
At the same time, the __construct() is callable actually:
The text was updated successfully, but these errors were encountered: