Home >Backend Development >PHP Tutorial >Remarks after reading the php manual version 2015-03-19
Classes and objects->Basic concepts:
1, ############################
::class
Since PHP 5.5 From now on, 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 parsing 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 refers to the PHP script when compiling The value can be obtained during the stage without relying on runtime information to evaluate.
PHP 5.3.0 has added support for Nowdoc declaration class attributes; a heredoc that does not contain variables is also possible, but it is wrong to contain variables.
new static() will follow the inheritance relationship, new is a 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, with Methods with the same class name are no longer used as constructors. This change does not affect classes that are not in the namespace.
namespace Foo;
class Bar {
public $a;
public function Bar() {
this->a;
}
}
$bar = new Bar();
echo $bar->getA(); //Empty; remove the namespace and output to here;
###
Since PHP 5.3 Starting from .0, a class can be referenced through a variable, and the value of the variable cannot be a keyword (such as self, parent and static).
With organization:
self, parent and static
public (public), protected (protected) or private (private)
The above introduces the remarks after reading the 2015-03-19 version of the PHP manual, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.