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)
?>
精彩评论