Function literal in PHP class

后端 未结 3 1879
挽巷
挽巷 2020-12-21 08:20

Take a look at this code, please:

$array = array(
    \'action\' => function () { echo \"this works\"; }
);

class Test {
    public $array = array(
              


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 08:55

    From the class it's a property !

    Rule from properties :

    Declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

    http://php.net/manual/en/language.oop5.properties.php

提交回复
热议问题