Add method in an std object in php

后端 未结 4 1447
说谎
说谎 2021-01-01 14:13

Is it possible to add a method/function in this way, like

$arr = array(
    \"nid\"=> 20,
    \"title\" => \"Something\",
    \"value\" => \"Somethi         


        
4条回答
  •  Happy的楠姐
    2021-01-01 14:53

    This is now possible to achieve in PHP 7.1 with anonymous classes

    $node = new class {
        public $property;
    
        public function myMethod($arg) { 
            ...
        }
    };
    
    // and access them,
    $node->property;
    $node->myMethod('arg');
    

提交回复
热议问题