note 125947 added to language.types.callable

From: Date: Mon, 22 Mar 2021 10:20:43 +0000
Subject: note 125947 added to language.types.callable
Groups: php.notes 
Request: Send a blank email to php-notes+get-219187@lists.php.net to get a copy of this message
If you pass a callable method to a function with a callable type declaration, the error message is misleading: <?php class X { protected function foo(): void {} } function bar(callable $c) {} $x = new X; $c = [$x, 'foo']; bar($c); ?> Error message will be something like "Argument #1 ($c) must be of type callable, array given" while the actual problem here is only the visibility of method "foo". All you need to do is changing it to public (or use a different approach, e.g. with a Closure). ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.247 (proxied: 213.155.83.52) ---- Manual Page -- http://php.net/manual/en/language.types.callable.php Edit -- https://master.php.net/note/edit/125947 Del: integrated -- https://master.php.net/note/delete/125947/integrated Del: useless -- https://master.php.net/note/delete/125947/useless Del: bad code -- https://master.php.net/note/delete/125947/bad+code Del: spam -- https://master.php.net/note/delete/125947/spam Del: non-english -- https://master.php.net/note/delete/125947/non-english Del: in docs -- https://master.php.net/note/delete/125947/in+docs Del: other reasons-- https://master.php.net/note/delete/125947 Reject -- https://master.php.net/note/reject/125947 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#219187) next »