ArrayObject::setFlags
Sets the flags that change the behavior of the ArrayObject.
<?php
void public ArrayObject::setFlags ( int $flags )
where,
$flags = The new ArrayObject behavior
?>
ATTENTION
This function allows the either use a bitmask, or named constants.
Using named constants is strongly encouraged.
ArrayObject::STD_PROP_LIST
Properties of the object have their normal functionality when accessed as list.
ArrayObject::ARRAY_AS_PROPS
Entries can be accessed as properties.
EXERCISE
<?php
$Dwarfs = [ 'Bashful' => 1 , 'Doc' => 2,
'Grumpy' => 3, 'Happy' => 4,
'Sneezy' => 5, 'Sleepy' => 6, 'Dopey' => 7];
$dwArrayObject = new ArrayObject($Dwarfs);
@var_dump($dwArrayObject->Dopey);
echo '<br><br>';
$dwArrayObject->setFlags(ArrayObject::STD_PROP_LIST);
@var_dump($dwArrayObject->Dopey);
?>
EXERCISE
<?php
$Dwarfs = [ 'Bashful' => 1 , 'Doc' => 2,
'Grumpy' => 3, 'Happy' => 4,
'Sneezy' => 5, 'Sleepy' => 6, 'Dopey' => 7];
$dwArrayObject = new ArrayObject($Dwarfs);
@var_dump($dwArrayObject->Dopey);
echo '<br><br>';
$dwArrayObject->setFlags(ArrayObject::ARRAY_AS_PROPS);
@var_dump($dwArrayObject->Dopey);
?>
EXERCISE
<?php
class Ao { }
const MYARRAY = [ 'Bashful' => 1, 'Doc' => 2,
'Grumpy' => 3, 'Happy' => 4,
'Sneezy' => 5, 'Sleepy' => 6, 'Dopey' => 7,
'Snow White' => 8];
$dwAO = new ArrayObject(MYARRAY);
$dwAO->setFlags(ArrayObject::ARRAY_AS_PROPS);
foreach(MYARRAY as $km => $vm)
{
var_dump($dwAO->$km);
echo ' => ' . $km . '<br>';
}
?>
RESULT
int(1) => Bashful
int(2) => Doc
int(3) => Grumpy
int(4) => Happy
int(5) => Sneezy
int(6) => Sleepy
int(7) => Dopey
int(8) => Snow White