PHP class and object _ PHP Tutorial

Source: Internet
Author: User
PHP class and object. PHP classes and objects have completely rewritten the object model since PHP5 for better performance and more features. This is the biggest change since PHP4. PHP5 has a complete object model. PHP class and object
Since PHP 5, the object model has been completely rewritten to get 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 an object reference, rather than copying the entire object.

Attribute:

The variable member of a class is called an attribute.

The attribute declaration keyword can be public protected private.

The variables in the attribute can be initialized, but the initial value must be a constant, not a formula.

For example

Private $ name = "tom"; // OK

Private $ name = "tom". "jack"; // error

Constants in the class:

The constant value must be a fixed value, not a variable, class attribute, mathematical operator, function call, etc.

Only const NAME = 'Tom 'can be used to define constants.

The access constant adopts the class: NAME outside self: NAME.

Automatic loading class:

Case column:

Index. php file
 GetName (); Name. php file
 


Since PHP 5, ghost has completely rewritten the object model to get better performance and more features. This is the biggest change since PHP 4. PHP 5 has a complete object model. PHP 5...

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.