Edit report at https://bugs.php.net/bug.php?id=61467&edit=1

 ID:                 61467
 User updated by:    david at grudl dot com
 Reported by:        david at grudl dot com
 Summary:            New "callable" typehint does not work (autoloading)
 Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 PHP Version:        5.4.0
 Block user comment: N
 Private report:     N

 New Comment:

Rasmus we're talking about two different things:

1) Error message "Must be callable, string given" means, that something other 
than string was expected. Do you agree? I think current message is confusing.

2) The behavior of typehint is subjective, of course. But it would be nice if 
you could consider, if it is really correct. We are talking about "type hint" - 
and checking of validity of a *type*. 

Type hint "array" means that the argument must be array. It's just about the 
type. Validity of array must be checked by function itself. The type hint 
"callable" I expect checks if argument is valid callable type (valid syntax), 
nothing more.


Previous Comments:
------------------------------------------------------------------------
[2012-03-23 13:35:48] ras...@php.net

Well, that's a very subjective thing. callable matches the default behaviour of 
is_callable(). In most cases when you pass a callable it is going to get 
called. 
If you want to implement lazy loading it is simple enough to do an is_callable 
syntax-check only in your method itself. The default had to be set to one or 
the 
other and we tend to set things to the common use case.

------------------------------------------------------------------------
[2012-03-23 12:55:09] david at grudl dot com

I understand its behavior, but I think it is wrong. Callable shouldn't check 
the existence of class, but only check argument is a syntactically correct. 
Otherwise it makes lazy-loading impossible. Not every callback is called. 

In addition, the non-existence of class results in confusing error message: 
"must be callable, string given". So "A::b" is not callable?

------------------------------------------------------------------------
[2012-03-23 05:18:22] ras...@php.net

But it only triggers the autoloader when you pass it something that looks 
exactly 
like A::b(). In this case it will go try to load 'A' in order to see if there 
is 
a b() method. If you pass it array(1,2,3) it will obviously not trigger the 
autoloader so I think your assertion that this will cause "major performance 
issues" is a bit drastic.

------------------------------------------------------------------------
[2012-03-21 23:57:25] david at grudl dot com

Possible fix is to change in file zend_execute.c on line 645 flag 
IS_CALLABLE_CHECK_SILENT to IS_CALLABLE_CHECK_SYNTAX_ONLY.

------------------------------------------------------------------------
[2012-03-21 21:58:51] david at grudl dot com

Sorry, in PHP 5.4 there is not "an instance of" in error message. But that's 
not the point.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=61467


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61467&edit=1

Reply via email to