0

How do I create classes and objects, and how do I call them?

0

4 Answers 4

8

Why show you when you can review the manual?

PHP: Classes and Objects

Sign up to request clarification or add additional context in comments.

1 Comment

It's better off to read the documentation anyways, plus it gives the op an insight where to reference any other topics in the future.
1
<?php class Widget { } $widget = new Widget(); ?> 

1 Comment

But seriously, what he said ^
1

see this

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

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

Comments

1

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) ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.