Warning when iterating with foreach over objects
2 posts
• Page 1 of 1
Warning when iterating with foreach over objects
When using this Example #1 with PHP Tools for Visual Studio, it complains at the foreach loops:
Obviously this is wrong, since it is an official example from PHP.
My suggestion would be to enhance the warning so that it knows a foreach loop is valid both over arrays and objects.
Cannot use object of type 'MyClass' as array.
Obviously this is wrong, since it is an official example from PHP.
My suggestion would be to enhance the warning so that it knows a foreach loop is valid both over arrays and objects.
- uwe
- Posts: 21
- Joined: October 10th, 2016, 8:39 am
Re: Warning when iterating with foreach over objects
Hi,
Thanks for the feedback.
Currently PHP Tools check whether the object implements Traversable interface so its iteration is handled by user's code.
Anyway you are right, it is possible to iterate through objects properties, but usually it is a sign of a possible error.
In a future version, we'll make this warning optional.
Thanks for the feedback.
Currently PHP Tools check whether the object implements Traversable interface so its iteration is handled by user's code.
Anyway you are right, it is possible to iterate through objects properties, but usually it is a sign of a possible error.
In a future version, we'll make this warning optional.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 93 guests