admin
admin copied to clipboard
PHP7 support: Cannot use String as class name
In PHP7 you can't have a class with the name String. http://php.net/manual/en/reserved.other-reserved-words.php
Cannot use SleepingOwl\Admin\Columns\Column\String as String because 'String' is a special class name
This causes a error 500: Internal server error as soon you access any of the Laravel routes or functions via tinker.
It's quite annoying how PHP has these reserved words when the things we want to name aren't actually related to the reserved functionality - e.g. a method on a class called list
. I find it crazy how PHP cannot realise that when we define a function called list
on a class we're not trying to use the built in list()
construct. Same goes for a namespaced class called String
. Oh well.
I imagine this could be a bad thing for a few other projects too especially as the list of reserved words include float
, numeric
and resource
(things like true
, false
and null
are a little more acceptable, though still not exactly sensible). I certainly think I've named a class Resource
a few times in the past!
@rawzone & @alexrussell If you need a temporary solution, I've forked this package because it seems that it's not being maintained anymore.. and updating to php7 broke 3 projects of mine because of this class String
..
You can use my fork, which renames String
to AdminString
You just need to replace the sleeping-owl/admin
with "jadjoubran/admin": "dev-development",
And then in case you get MAC is invalid error, you just need to clear your cookies and the error will be fixed (Admin package trying to read previous cookies)
@jadjoubran Nice one! I'll for sure take a look at your fork as I kind of stranded in a few projects my self and didn't want to fork the whole project as I hope(d) they would refactor the class in time for the php7 release.
no need replace repo just use "repositories": [ { "type": "git", "url": "https://github.com/cxbyte/admin.git" // or other forked repo } ],
"require": {
......
"sleeping-owl/admin": "dev-master",
......
},
This is a most annoying bug and has to be fixed somehow. I had to rename String into AdminString everywhere in the project.
-
rename file SleepingOwl\Admin\Columns\Column\String.php to SleepingOwl\Admin\Columns\Column\StringColumn.php
-
rename Class in this file class Column extends BaseColumn To class StringColumn extends BaseColumn
-
Add in SleepingOwl\Admin\Columns\Column.php public static function __callStatic($method, $params) { if ($method == 'string') { $method = 'stringColumn'; } $column = null;
That's all
I follow antonim solution, it works but after that you need to execute
composer dump-autoload -o
otherwise laravel application continue to search "String" class and gives error.