Current Travis-CI PHP7 builds throw the following error when executing the following code:
PHP 7 Fatal error: static::class cannot be used for compile-time class name resolution
trait EloquentValidatingTrait
{
// Some declarations skipped
/**
* Eloquent will call this on model boot
*/
public static function bootEloquentValidatingTrait()
{
// Calling Model::saving() and asking it to execute assertIsValid() before model is saved into database
$savingCallable = [static::class, 'saving'];
$validationCallable = [static::class, 'assertIsValid'];
forward_static_call($savingCallable, $validationCallable);
}
Is that a temporary bug or a future feature I missed? Notes below this RFC says it should work (and it does in 5.5 and 5.6).
SomeClass::class will return the fully qualified name of SomeClass including the namespace. This feature was implemented in PHP 5.5. It's very useful for 2 reasons. You can use the use keyword to resolve your class and you don't need to write the full class name.
To create an instance of a class, the new keyword must be used. An object will always be created unless the object has a constructor defined that throws an exception on error. Classes should be defined before instantiation (and in some cases this is a requirement).
Definition and UsageThe new keyword is used to create an object from a class.
Fixed this bug via http://git.php.net/?p=php-src.git;a=commitdiff;h=1d3f77d13d2b457bdf1bc52045da4679741e65cb
The mistake was simple... I had in compile time constant resolution optimization set the mode to force succeed or die (a simple boolean to a function call). That mode is needed for static expressions (like const FOO = static::class;
must fail).
Set that to zero and now it works fine. Just pull the newest master for a fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With