PHP 8.5.0 Alpha 4 available for testing

Voting

: max(nine, one)?
(Example: nine)

The Note You're Voting On

5imun at github dot com
3 years ago
Example of setting up static property in child class from parent only if it isn't already defined, many people would expect that output will be "Foo Bar" but instead we get "Foo Foo":

<?php
class Foo
{
public static
string $A;

public static function
init() {
return
"Foo";
}
public static function
get() {
if (!isset(static::
$A)) {
static::
$A = static::init();
}
return static::
$A;
}
}

class
Bar extends Foo {
public static function
init() {
return
"Bar";
}
}

$foo = new Foo();
$bar = new Bar();

echo
$foo->get();
echo
$bar->get();
?>

Output:
Foo
Foo

<< Back to user notes page

To Top