wright67uk Posted April 17, 2013 Share Posted April 17, 2013 Is there a work around for when I want to use construct keywords within my code? Eg. return $array_name[quantity]="$_POST[quantity]"; $array_name[invoice]="$_POST[invoice]"; $array_name[custom]="$_POST[custom]"; // $array_name[return] = http://workaround.how Quote Link to comment https://forums.phpfreaks.com/topic/277080-using-reserved-words/ Share on other sites More sharing options...
Barand Posted April 17, 2013 Share Posted April 17, 2013 String array keys should always be quoted eg $array_name['quantity']. Then you have no issues anyway $arr = array(); $arr['return'] = 42; echo $arr['return']; // 42 Quote Link to comment https://forums.phpfreaks.com/topic/277080-using-reserved-words/#findComment-1425468 Share on other sites More sharing options...
seandisanti Posted April 17, 2013 Share Posted April 17, 2013 Yeah, either it's a variable and will be preceeded by '$' or it's a literal string that won't be confused for a keyword anyway. The only way you could have problems is if you decided you wanted to use a reserved word as the name of a constant AND you decided not to follow capitalization conventions, at which point you'll have made multiple intentional decisions to cause yourself problems and really shouldn't be surprised when you succeed (at failing) Quote Link to comment https://forums.phpfreaks.com/topic/277080-using-reserved-words/#findComment-1425501 Share on other sites More sharing options...
requinix Posted April 18, 2013 Share Posted April 18, 2013 The only way you could have problems is if you decided you wanted to use a reserved word as the name of a constant AND you decided not to follow capitalization conventions,Constants may be case-sensitive (by default) but keywords aren't. define("RETURN", 123); echo RETURN; // unexpected T_RETURN Quote Link to comment https://forums.phpfreaks.com/topic/277080-using-reserved-words/#findComment-1425506 Share on other sites More sharing options...
seandisanti Posted April 18, 2013 Share Posted April 18, 2013 good call, I totally forgot about that. Quote Link to comment https://forums.phpfreaks.com/topic/277080-using-reserved-words/#findComment-1425656 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.