MENU
Classes and Objects
Not to be confused with the HTML/CSS ‘class’ attribute, a class in PHP may be regarded as a data type. It can contain properties (variables) and methods (functions). Use new to instantiate an object out of a class. Use -> on an instantiated object to access the object properties and methods. A string may be used as the class name, the method name or the object name.RESETRUNFULL
<!DOCTYPE html>
<html>
<head></head>
<body><?php
class MyClass{
public $v=10; // a property
function shout(){ // a method
echo "Hello World! <br />";
}
function smile(){ // another method
echo "Smile World! <br />";
}
}
$test=new MyClass;
$test->shout();
echo $test->v."<br />";
$s="MyClass";
$test2=new $s;
$test2->smile();
$s="shout";
$test->$s();
$s="test";
$$s->smile();
?></body>
</html>