How can I declare a list of objects in php as a private instance variable?
In Java the declaration would look something like this
private ArrayList<Object> ls
and the constructor would have this
ls = new ArrayList<Object>();
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP allocates memory dynamically and what’s more, it doesn’t care what sort of object you store in your array.
If you want to declare your array before you use it something along these lines would work:
Then you can store any object you like in your variable $myArray. Many people find this a strange concept to grasp after working in a strict language like java.