Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel PHP版本错误_Php_Class_Laravel_Laravel 5.1 - Fatal编程技术网

Laravel PHP版本错误

Laravel PHP版本错误,php,class,laravel,laravel-5.1,Php,Class,Laravel,Laravel 5.1,我在使用Laravel5.1版本时遇到了问题。我用PHP5.5.9在Ubuntu平台上构建了它。然后我得到了以下错误: PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting ')' 以下是返回错误的代码: <?php interface foo { } class class_with_method_that_declares_anonymous_class { public

我在使用Laravel5.1版本时遇到了问题。我用PHP5.5.9在Ubuntu平台上构建了它。然后我得到了以下错误:

 PHP Parse error:  syntax error, unexpected 'class' (T_CLASS), expecting ')'
以下是返回错误的代码:

 <?php
 interface foo {
 }

 class class_with_method_that_declares_anonymous_class
 {
     public function method()
     {
         $o = new class { public function foo() {} };
         $o = new class{public function foo(){}};
         $o = new class extends stdClass {};
         $o = new class extends stdClass {};
         $o = new class implements foo {};
     }
 }

在PHP中,不能在类方法中声明类。

可以是任意数量的类,特别是因为它太大了。查看错误的其余部分(文件,通常列出行号)以查看调用它的位置。或者您可以在主laravel目录的命令行中尝试此操作:
find-name\*.php-exec php-l“{}”\|egrep-v'No syntax'
提供错误指定的代码片段,以帮助您,错误是模糊的。好的,我在上面添加了代码。@OnurGöker您使用的是匿名类吗?如果是,那么您需要将PHP verion升级到PHP7。之后,您可以使用上面的代码..在PHP7中添加了匿名类此代码中的用法在PHP5.5.X中可用请参见:我应该在安装了该版本的PHP后结束我的句子。是我的错,我想这应该是我的一个更好的答案。
 <?php
 class Test {
     public function methodOne() {
        $foo = new class {
            public function method_in_anonymous_class() {
                return true;
            }
        };

        return $foo->method_in_anonymous_class();
    }

    public function methodTwo() {
        return false;
    }
 }