PHP လို့ ခေါ်တဲ့ Keyword ပါ။
ဥပမာ
အငြင်းအခုံအဖြစ် ပြန်ခေါ်နိုင်သော လုပ်ဆောင်ချက်ကို လိုအပ်ရန် ခေါ်ဆိုနိုင်သောကို သုံးပါ-
<?php
function printFormatted(callable $format, $str) {
echo $format($str);
echo "<br>";
}
function exclaim($str) { return $str . "!"; }
printFormatted("exclaim", "Hello World");
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
callable
လုပ်ဆောင်ချက်အငြင်းအခုံတစ်ခုကို လုပ်ဆောင်ချက်တစ်ခုအား ရည်ညွှန်းရန် အဓိကစကားလုံးကို အသုံးပြုသည် ။
ခေါ်ဆိုနိုင်သော အရာသည် အောက်ပါတို့ထဲမှ တစ်ခု ဖြစ်နိုင်သည်-
- အမည်မသိ function တစ်ခု
- လုပ်ဆောင်ချက်တစ်ခု၏အမည်ပါရှိသော စာကြောင်းတစ်ခု
- static class method ကိုဖော်ပြသည့် array တစ်ခု
- အရာဝတ္ထုနည်းလမ်းကို ဖော်ပြသည့် array တစ်ခု
နောက်ထပ် ဥပမာများ
ဥပမာ
ခေါ်ဆိုနိုင်သော အမျိုးအစားအမျိုးမျိုးကို အသုံးပြုခြင်း-
<?php
function printFormatted(callable $format, $str) {
echo
$format($str);
echo "<br>";
}
class MyClass {
public static function
ask($str) {
return $str . "?";
}
public function brackets($str) {
return "[$str]";
}
}
// An anonymous function
$func = function($str)
{ return substr($str, 0, 5); };
printFormatted($func , "Hello World");
// A string containing the name of a function
printFormatted("strtoupper", "Hello World");
// An array describing a
static class method
printFormatted(["MyClass", "ask"], "Hello World");
// An array describing an object method
$obj = new MyClass();
printFormatted([$obj, "brackets"], "Hello World");
?>
❮ PHP သော့ချက်စာလုံးများ