
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP Casting Variable as Object type in foreach Loop
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 ){ }
- Related Articles
- PHP foreach Loop.
- Multiple index variables in PHP foreach loop
- Stripping last comma from a foreach loop in PHP?
- The internal working of the ‘foreach’ loop in PHP
- foreach Loop in C#
- Type casting in JavaScript.
- How to use a variable inside a Foreach-Object Parallel?
- Type Casting operators in C++
- Java Type Casting Examples
- Using foreach loop in arrays in C#
- Iterating C# StringBuilder in a foreach loop
- Explicit Type Casting in Python Language
- const_cast in C++ - Type casting operators
- Explicit type casting operator in C++
- What is Type casting in C#?

Advertisements