Classes and objects in PHP

Source: Internet
Author: User
Tags object constant header new features object model php file variable access
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 ');
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.