开发者

How do I create classes and objects in PHP

开发者 https://www.devze.com 2023-02-06 03:12 出处:网络
How do I create classes and ob开发者_如何学运维jects, and how do I call them?Why show you when you can review the manual?

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

精彩评论

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

关注公众号