PHP classes and objects

Source: Internet
Author: User

PHP classes and objects
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 the class is called the attribute declaration keyword. The variable in the public protected private property can be initialized, but the initial variable must be a constant and cannot be a computing formula such as private $ name = "tom "; // okprivate $ name = "tom ". "jack"; // constant in the error class: the constant value must be a fixed value, not a variable, class attribute, mathematical operator, function calls can only use const NAME = 'Tom '; the constant access constant is defined inside the class and the class: Case column is automatically loaded using classname: NAME outside the class:

Index. php file <? Phpheader ("content-type: text/html; charset = UTF-8"); function _ autoload ($ className) {require_once $ className. '. php ';} $ obj = new Name (); $ obj2 = new User (); var_dump ($ obj-> getName (); Name. PHP file <? Phpheader ("content-type: text/html; charset = UTF-8"); class Name {function getName () {return "Ouyang Jun" ;}} User. php file <? Phpheader ("content-type: text/html; charset = UTF-8"); class User {function getUser () {return array ('ouangjun', 'jpp ');}}

 


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.