Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using number as a table column name - ErrorException in VarCloner.php line 74 #8710

Closed
digitlimit opened this issue May 12, 2015 · 12 comments

Comments

@digitlimit
Copy link

Its presently not possible to use MYSQL Database tables with numeric column names.

Most applications requires numeric table column names as you can see in the case of this stackoverflow question http://stackoverflow.com/questions/30162545/hide-number-field-from-eloquent-model-in-laravel/30162980#30162980

In attempt to answer the question above I added a column named '23' in a certain table which resulted in the error below:


ErrorException in VarCloner.php line 75:
Undefined offset: 23

at HandleExceptions->handleError('8', 'Undefined offset: 23', '/home/vagrant/Code/project/vendor/symfony/var-dumper/Symfony/Component/VarDumper/Cloner/VarCloner.php', '74', array('var' => object(Collection), ' ...truncated

I noticed that replacing this code in VarCloner.php line 74


 if ($zval['zval_isref'] = $queue[$i][$k] === $cookie) {
                        $zval['zval_hash'] = $v instanceof Stub ? spl_object_hash($v) : null;
                    }

with


if ($zval['zval_isref'] = (isset($queue[$i][$k])) ? ($queue[$i][$k] === $cookie) : false) {
                        $zval['zval_hash'] = $v instanceof Stub ? spl_object_hash($v) : null;
                    }

resolves the issue, however this is a hack.

Please can the framework be updated to make using numeric table column names possible.

NB: Am using MySQL Database

@lukasgeiter
Copy link
Contributor

One SO question doesn't mean "most applications" use numeric column names.

@digitlimit
Copy link
Author

@lukasgeiter please I don't understand

@lukasgeiter
Copy link
Contributor

I highly doubt that as you say "most applications" have numeric column names. Besides that I'd also consider this quite bad practice since it's almost impossible that a numeric value is a descriptive name for table column.

@digitlimit
Copy link
Author

I totally agree with you about this being a bad practice however according to this question http://stackoverflow.com/questions/30162545/hide-number-field-from-eloquent-model-in-laravel/30162980#30162980, the developer also mentioned and I quote "I have field names in my model that are numbers (I don't have control over it's names)".. which means he cannot change it

@lukasgeiter
Copy link
Contributor

Sure that still doesn't mean that this is a common use case. Don't get me wrong, I don't think we shouldn't fix this, but it has rather low priority in my eyes.

@digitlimit
Copy link
Author

Yes sure. I don't think I will ever use number as column but for the sake of future I think it should be addressed.
Since its possible to use number as column name in MySQL database table, will be nice if Laravel can handle numeric column names. I think its key.

@lukasgeiter
Copy link
Contributor

The error and "fix" you posted here in the issue have nothing to do with the framework itself. It's a problem in the Symfony VarDumper. However things don't really work in Eloquent as well. For example hidden and other functions are not functioning correctly.

Unfortunately I believe this is just to PHPs type handling and can't be fixed easily...

@digitlimit
Copy link
Author

This's my first time of opening an issue here. Actually thought it could be fixed within a short time.

@GrahamCampbell
Copy link
Member

We're open to PRs.

@digitlimit
Copy link
Author

@GrahamCampbell Please I don't understand your reply "We're open to PRs." ?

@GrahamCampbell
Copy link
Member

It means if you want to fix it, feel free. Even a partial fix as a PR might allow someone else to finish up.

@digitlimit
Copy link
Author

@GrahamCampbell what worked for me was a Hack, which am sure is not good enough.

Presently this is not possible in Laravel as seen in this line of code located in vendor\symfony\var-dumper\Symfony\Component\VarDumper\Cloner\VarCloner.php at line 74.


  if ($zval['zval_isref'] = $queue[$i][$k] === $cookie) {
                        $zval['zval_hash'] = $v instanceof Stub ? spl_object_hash($v) : null;
                    }

Here is the hack.


  if ($zval['zval_isref'] = (isset($queue[$i][$k])) ? ($queue[$i][$k] === $cookie) : false) {
                        $zval['zval_hash'] = $v instanceof Stub ? spl_object_hash($v) : null;
                    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants