PHP 8.5.0 Alpha 4 available for testing

Voting

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

The Note You're Voting On

Pieter Frenssen
1 year ago
To check in a trait if a constant is defined in the class using the trait, prepend the constant name with `self::class`:

<?php

trait MyTrait {
public function
checkConstant() {
assert(defined(self::class . "::MY_CONSTANT"));
print
self::MY_CONSTANT;
}
}

class
MyClass {
use
MyTrait;
protected const
MY_CONSTANT = 'my value';
}

$class = new MyClass();
$class->checkConstant();
?>

<< Back to user notes page

To Top