0

I've was working on some old parts of a website and found myself in a situation where I have to run the following code

<?=($stone->2_way)? 'checked' : ''?>

Attempting to do this causes the page to crash while this

<?=($stone->rectangular)? 'checked' : ''?>

doesn't. I'm wondering if it is because the variable starts with a number? I can var_dump the stone object and get

object(Cut_Stone)#54 (6) {
  ["errors"]=>
  NULL
  ["attributes":"ActiveRecord\Model":private]=>
  array(13) {
    ["stone_id"]=>
    int(24)
    ["stone_name"]=>
    string(11) "Test Stone "
    ["active"]=>
    int(1)
    ["rectangular"]=>
    int(1)
    ["2_way"]=>
    int(1)
    ["3_piece_radius"]=>
    int(1)
    ["3_piece_straight"]=>
    int(1)
    ["wedge"]=>
    int(1)
    ["partial_wash"]=>
    int(1)
    ["pier_cap"]=>
    int(1)
    ["pier_cap_w_flat"]=>
    int(1)
    ["radiused_hearth"]=>
    int(1)
    ["total_washed"]=>
    int(1)
  }
  ["__dirty":"ActiveRecord\Model":private]=>
  array(0) {
  }
  ["__readonly":"ActiveRecord\Model":private]=>
  bool(false)
  ["__relationships":"ActiveRecord\Model":private]=>
  array(0) {
  }
  ["__new_record":"ActiveRecord\Model":private]=>
  bool(false)
}

Also it is important to note that this object has been used in other places without fail, so I don't really get what is going on here.

putvande
  • 15,068
  • 3
  • 34
  • 50
ed209
  • 828
  • 2
  • 14
  • 30
  • why can i not find anything saying "php variables allow numbers at the beginning" PHP.net says it's invalid – ddavison Aug 14 '13 at 18:17
  • Possible duplicate of [How to access object properties with names like integers?](http://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers) – rink.attendant.6 Aug 14 '13 at 18:19

1 Answers1

4

Try using brackets and quotes around the property name:

<?=($stone->{'2_way'})? 'checked' : ''?>
Divey
  • 1,699
  • 1
  • 12
  • 22
  • Thank God for you .... I was really worried because this type of thing is all over the site... Correct answer – ed209 Aug 14 '13 at 18:18