
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Casting Variable as Object Type in Foreach Loop in PHP
This depends on the IDE that is being used. For example, Netbeans and IntelliJ can enable the usage of @var in a comment −
/* @var $variable ClassName */ $variable->
This way, the IDE would know that the ‘$variable’ is a class of the ClassName after the hint ‘->’ is encountered.
In addition, an @return annotation can be created with a method that specifies that the return type will be an array of ClassName objects. This data can be accessed using a foreach loop that fetches the values of the objects −
function get_object_type() { return $this->values; } foreach( $data_object-> values as $object_attribute ){ }
Advertisements