Hope PHP Handbook 2015-03-19 version Reserve note

Source: Internet
Author: User
See PHP Handbook 2015-03-19 version Reserve note

Basic concepts of classes and objects:
1,#############################
:: Class
Since PHP 5.5, keyword class can also be used to parse the class name. With Classname::class you can get a string that contains the fully qualified name of the class ClassName. This is especially useful for classes that use namespaces.
Example #7 Class name resolution as stated in the docs is:
Namespace NS {
Class ClassName {
}
Echo Classname::class;
}
?>
The above routines will output:
Ns\classname


2,#############################
Just to being clear:the correct the validating a classname, as stated in the docs are:
$valid = Preg_match ('/^[a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]*$/', $className);

3,#############################
A variable in a property can be initialized, but the initialized value must be a constant, where a constant is a PHP script that can get its value at compile time without relying on runtime information to evaluate
PHP 5.3.0 adds support for Nowdoc declaring class properties, and Heredoc that do not contain variables is also possible, including variables that are wrong.


New static () follows the inheritance relationship, and new is a subclass
New self () is not inherited, and new is the class where the word self is located


###
As of PHP 5.6 you can finally define constant using the math expressions, like this one:

Class MyTimer {
Const SEC_PER_DAY = 60 * 60 * 24;
}

?>

###
From PHP 5.3.3, in a namespace, a method with the same name as the class name is no longer a constructor. This change does not affect classes that are not in the namespace.
namespace Foo;
Class Bar {
public $a;
Public Function Bar () {
$this->a = ' to here ';
}
Public Function Geta () {
return $this->a;
}
}
$bar = new Bar ();
echo $bar->geta (); Empty Remove the namespace and output to here;



###
From PHP 5.3.0, the class can be referenced by a variable, and the value of the variable cannot be a keyword (such as self,parent and Static).




With finishing:
Self,parent and Static
Public (publicly), protected (protected) or private (private)

  • 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.