9

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).

Dan
  • 10,614
  • 5
  • 24
  • 35
Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156
  • I'm not sure if this is a valid question, but do you have this function inside the Model class or is this in a class that extends Model? – Cayce K Jun 03 '15 at 20:37
  • @CayceK This is a method of a trait, used by the model. – Vladislav Rastrusny Jun 03 '15 at 20:38
  • Would you be willing to show saving? – Cayce K Jun 03 '15 at 20:46
  • don't know if it could be of some use, I created this: http://3v4l.org/eEnUb to try to play with the code – marcosh Jun 03 '15 at 21:09
  • 1
    This is a bug that was introduced [recently](http://3v4l.org/CpKdA). It looks like [this commit](http://git.php.net/?p=php-src.git;a=commitdiff;h=69b54ba926b714dff0f8b54bea385e9a278c5849) may have *accidentally* broken things. – salathe Jun 03 '15 at 21:12
  • 1
    Raised as [bug #69754](https://bugs.php.net/bug.php?id=69754) for those who want to keep track. – salathe Jun 03 '15 at 21:18
  • 4
    I'm voting to close this question as off-topic because it's a PHP bug. :) – salathe Jun 03 '15 at 21:20
  • 1
    Hmm… Looks like I have introduced that mistake… will fix it later. [Also: thanks for testing PHP 7!] – bwoebi Jun 03 '15 at 21:21
  • 1
    This question should not have been closed. [Questions caused by toolchain bugs are **on-topic** for Stack Overflow.](//meta.stackoverflow.com/a/277480/2747593) Voting to re-open. – Scott Weldon Dec 30 '16 at 17:55

1 Answers1

7

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.

bwoebi
  • 23,637
  • 5
  • 58
  • 79