RedBean crash if field begin with number

38 views Asked by At

I have a table called User with a field called 10kssc of type integer

If I do this on an existing bean

echo $user->10kssc;

The code died with just an empty tab

I can see this is in the docs for version 3 which doesnt suggest a field name cant start with a number

http://redbeanphp.com/manual3_0/schema

I cant find anything in the docs for v4

http://redbeanphp.com/welcome

In the mysql manual it says 'Identifiers may begin with a digit but unless quoted may not consist solely of digits.'

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

Naturally i can change the field name but you only progress by understanding your 'mistakes'

Any help in advance is much appreciated

Thanks

1

There are 1 answers

0
Giedrius On BEST ANSWER

In PHP you can not access object property if it starts with numbers (is not legal variable). You can use curly bracket syntax (section Complex (curly) syntax) as workaround in order to escape property name. In you your case it would be:

$user->{'10kssc'}