Defining class methods in PHP

后端 未结 8 1293
臣服心动
臣服心动 2021-01-05 10:55

Is it possible in PHP (as it is in C++) to declare a class method OUTSIDE the class definition?

8条回答
  •  逝去的感伤
    2021-01-05 11:11

    Yes it is possible to add a method to a PHP class after it is defined. You want to use classkit, which is an "experimental" extension. It appears that this extension isn't enabled by default however, so it depends on if you can compile a custom PHP binary or load PHP DLLs if on windows (for instance Dreamhost does allow custom PHP binaries, and they're pretty easy to setup).

    bar('Hello world!');
    

    Example from the PHP manual:

    add(12, 4);
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题