开发者

How do I create classes and objects in PHP

How do I create classes and ob开发者_如何学运维jects, and how do I call them?


Why show you when you can review the manual?

PHP: Classes and Objects


<?php
class Widget {

}

$widget = new Widget();
?>


see this

http://www.php.net/manual/en/language.oop5.basic.php

http://evolt.org/node/48911/


If you want to create a class which objects are callable (in PHP 5.3), than you need to defined __invoke magic method in your class, e.g.

<?php 

class MyClass {

     public function __invoke($x)  {
        var_dump($x);
    }
}

$myObject = new MyClass();
$myObject(2);

// output: init(2)

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜