PHP 8.5.0 Alpha 1 available for testing

Voting

: min(nine, zero)?
(Example: nine)

The Note You're Voting On

php at itronic dot at
15 years ago
If you call a static getInstance() function to create a instance of a class from another class, this function have to be static, if it is not static the original name of the caller class and not of the current class get returned.

example:

<?php

class a {
function
getXName() {
return
x::getClassName();
}
function
getXStaticName() {
return
x::getStaticClassName();
}

}

class
b extends a {
}

class
x {
public function
getClassName() {
return
get_called_class();
}
public static function
getStaticClassName() {
return
get_called_class();
}
}

$a = new a();

$b = new b();

echo
$a->getXName(); // will return "a"
echo $b->getXName(); // will return "b"

echo $a->getXStaticName(); // will return "x"
echo $b->getXStaticName(); // will return "x"

?>

<< Back to user notes page

To Top