Tran Dinh Trong's Blog
Stuydy and share
parent:: AND self::
22/03/2012
Posted by on PHP supports two reserved class names that make it easier when writing OO
applications. PHP supports two reserved class names that make it easier when writing OO
applications. self:: refers to the current class and it is usually used to access
static members, methods, and constants. parent:: refers to the parent class and
it is most often used when wanting to call the parent constructor or methods.
- self:: refers to the current class and it is usually used to access
static members, methods, and constants. - parent:: refers to the parent class and
it is most often used when wanting to call the parent constructor or methods. - It may also be used to access members and constants.
class Ancestor {
const NAME = "Tran Dinh Trong";
function __construct() {
print "In ". self::NAME." Construct";
}
}
class Child extends Ancestor{
const NAME = "Tran Dinh Thien";
function __construct() {
parent::__construct();
print "In ".self::NAME." Construct";
}
}
$child = new Child();
In Tran Dinh Trong Construct
In Tran Dinh Thien Construct