In a php
code I found the code snippet:
class GF_Field extends stdClass implements ArrayAccess {
if ( is_array( $this->inputs ) ) {
foreach ( $this->inputs as $input ) {
But I don't know what is inputs
come from.
Any help would be highly appropriated.
EDIT:
The programmer made two ambiguous step, which made me harder to find the declaration:
foreach ( $this->inputs as &$input ) { $input = something
You are ommiting code here, but for short answer, you don't have to explicitally define the attributes in PHP. You can create only for the object, and it will work like this:
class AnyClass extends stdClass {
public function print() {
if ( is_array( $this->inputs ) ) {
foreach ( $this->inputs as $input ) {
echo $input;
}
}
}
}
$obj = new AnyClass;
$obj->inputs = [1,2,3];
$obj->print();
It will output 123
.
stdClass is a generic class for PHP objects. ArrayAccess is a PHP interface. So, in your case, the $inputs
is probably not defined anywhere in the class, or class tree, but is "defined" directly in the object instance.