PHP 8.5.0 Alpha 4 available for testing

Voting

: max(zero, two)?
(Example: nine)

The Note You're Voting On

gazianis2200 at gmail dot com
1 year ago
<?php
/**
*access a constant from outside a class
*/
class Foo{
public const
A = "Constant A";
}
echo
Foo::A;
echo
"\n";

/**
*access a constant within its own class
*/

class Bar{
public const
A = "Constant A";
public function
abc(){
echo
self::A;
echo
"\n";
}
}

$obj = new Bar;
$obj->abc();

/**
*access a constant within her child class
*/

class Baz extends Bar{
public function
abc(){
echo
parent::A;
}
}
$obj = new Baz;
$obj->abc();

//Static property and static method also follows this principle.

<< Back to user notes page

To Top