sleeping-owl / admin

Administrative interface builder for Laravel
http://sleeping-owl.github.io/
MIT License
504 stars 259 forks source link

PHP7 support: Cannot use String as class name #267

Open rawzone opened 9 years ago

rawzone commented 9 years ago

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.

alexrussell commented 8 years ago

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!

jadjoubran commented 8 years ago

@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 commented 8 years ago

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)

rawzone commented 8 years ago

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

cxbyte commented 8 years ago

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",
    ......
},
VladimirBubar commented 8 years ago

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

antonim commented 7 years ago
  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

s6carlo commented 7 years ago

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.