The object model has been completely rewritten since PHP 5 for better performance and more features. This is the biggest change since PHP 4. PHP 5 has a complete object model. New features in PHP 5 include access control, abstract classes and final classes and methods, additional magic methods, interfaces, object replication, and type constraints. PHP treats objects in the same way as references and handles, that is, each variable holds a reference to the object, not a copy of the entire object. Properties: A variable member of a class is called a property property declaration keyword can be public protected a variable in a private property can be initialized, but the initial word must be a constant cannot be a calculation such as private $name = "Tom"; OK private $name = "Tom". Jack "; Constants in the error class: The value of a constant must be a fixed value, not a variable, a property of a class, a mathematical operator, a function call, and so on can only use the const name= ' Tom '; way to define constant access constants within a class using Self::name External use of Classname:name automatic loading class: Case column:
index.php file
<?php
header ("Content-type:text/html;charset=utf-8");
function __autoload ($className) {
require_once $className. php ';
}
$obj = new Name ();
$obj 2 = new User ();
Var_dump ($obj->getname ());
name.php file
<?php
header ("Content-type:text/html;charset=utf-8");
Class name{
function GetName () {return
"Ouyangjun";
}
}
user.php file
<?php
header ("Content-type:text/html;charset=utf-8");
Class user{
function GetUser () {return
array (' Ouyangjun ', ' jpp ');
}