Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Square brackets with a class name inside in PHP

I’m debugging someone else old code, I think it has been made under php5 and I’m debugging after migrating to php8.
The question I have is just about a syntax I haven’t seen before, I don’t know how to google and I can’t test.
I found this:

$aSelectedAssignmentFields=$advanced_options[assignment_fields];

And I don’t know what it means. The value inside of the square brackets doesn’t have a dollar sign or quotes. There is a class with that name but because of other issues I can’t run it and check if that’s right or wrong. It would be weird that is wrong, it would not that is outdated and in case it’s right I would like to know what does it mean.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks

>Solution :

It’s impossible to do more than guess without more context; and may be impossible to be certain without a time machine to go back and ask the original developer (if you asked them now, I doubt they’d remember). I can think of two possibilities:

  1. It was intended to be a constant, and the definition has got lost somewhere. Most people right constants in upper-case, but there’s never been anything in PHP itself to enforce that.
  2. It was intended to be a string, as in $aSelectedAssignmentFields=$advanced_options['assignment_fields']; Prior to PHP 8, there was an odd "feature" where an unquoted name which didn’t match a constant would implicitly act like a quoted string. In PHP 5, it would have given a Notice; in PHP 7, a Warning; and in PHP 8, the functionality was removed and you get an error.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading