Php 5.4 te gelen yeni bir özellik de “callable” typehinti.
Callable ile , “çağrılabilir” bir parametre geleceğini ifade etmiş oluyorsunuz. ve istediğiniz zaman bunu çağırabiliyorsunuz.
class Meyve
{
function __construct($name)
{
$this->name = $name;
}
public function selam()
{
return "Selam " . $this->name;
}
}
//fonksiyonumuzu tanımlarken $f yi callable olarak cast ediyoruz. (hint ediyoruz)
function selam(callable $f) {
//ve bu şekilde çağırabiliyoruz.
$f();
}
selam([new Meyve("Armut"), 'selam']);
php 5.4 callable typehint | Boğaç Aslanyürek
[…] class Meyve { function __construct(… Devamı için : php 5.4 callable typehint […]
php 5.4 callable typehint | Kara Kule
[…] class Meyve { function __construct(… Devamı için : php 5.4 callable typehint […]
php 5.4 callable typehint | kodluyorum
[…] class Meyve { function __construct(… Devamı için : php 5.4 callable typehint […]