admin icon indicating copy to clipboard operation
admin copied to clipboard

PHP7 support: Cannot use String as class name

Open rawzone opened this issue 9 years ago • 8 comments

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.

rawzone avatar Oct 12 '15 21:10 rawzone

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!

alexrussell avatar Nov 26 '15 10:11 alexrussell

@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",

jadjoubran avatar Dec 07 '15 20:12 jadjoubran

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 avatar Dec 07 '15 20:12 jadjoubran

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

rawzone avatar Dec 07 '15 21:12 rawzone

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",
    ......
},

cxbyte avatar Dec 30 '15 12:12 cxbyte

This is a most annoying bug and has to be fixed somehow. I had to rename String into AdminString everywhere in the project.

VladimirBubar avatar Mar 01 '16 15:03 VladimirBubar

  1. rename file SleepingOwl\Admin\Columns\Column\String.php to SleepingOwl\Admin\Columns\Column\StringColumn.php

  2. rename Class in this file class Column extends BaseColumn To class StringColumn extends BaseColumn

  3. Add in SleepingOwl\Admin\Columns\Column.php public static function __callStatic($method, $params) { if ($method == 'string') { $method = 'stringColumn'; } $column = null;

That's all

antonim avatar May 21 '17 11:05 antonim

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.

s6carlo avatar Jun 22 '17 13:06 s6carlo