Home > Backend Development > PHP Tutorial > Notes after reading the php manual 2015-03-19 version, php2015-03-19_PHP tutorial

Notes after reading the php manual 2015-03-19 version, php2015-03-19_PHP tutorial

WBOY
Release: 2016-07-13 09:52:17
Original
863 people have browsed it

Remarks after reading the php manual 2015-03-19 version, php2015-03-19

Classes and objects->Basic concepts:
1, #### ########################
::class
Since PHP 5.5, the keyword class can also be used for class name resolution. Using ClassName::class you can get a string containing 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 routine will output:
NSClassName


2,################ ############
Just to be clear: the correct way of validating a classname, as stated in the docs is:
$valid = preg_match('/^[a-zA -Z_x7f-xff][a-zA-Z0-9_x7f-xff]*$/', $className);

3,################# ############
Variables in attributes can be initialized, but the initialized value must be a constant. The constant here means that the PHP script can get its value during the compilation phase without relying on Only runtime information can be evaluated
PHP 5.3.0 adds support for Nowdoc declaration class attributes; heredoc without variables is also possible, but it is wrong to include variables.


new static() will follow the inheritance relationship, new is the subclass
new self() will not be inherited, new is the class where the word self is located


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

class MyTimer {
const SEC_PER_DAY = 60 * 60 * 24;
}

?>

###
Since PHP 5.3.3, in the namespace, methods with the same name as the class name are no longer as 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;



###
Since PHP 5.3.0, classes can be referenced through variables. The value of this variable cannot be keywords (such as self, parent and static).




With organization:
self, parent and static
public (public), protected (protected) or private (private)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1009709.htmlTechArticleRemarks after reading the php manual 2015-03-19 version, php2015-03-19 Classes and Objects-Basic Concepts: 1. ############################# ::class Since PHP 5.5, the keyword class can also be used to parse class names. ..
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template