phpday 2027 - Call for Papers

CachingIterator::getFlags

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

CachingIterator::getFlags — Get flags used

Beschreibung

public function CachingIterator::getFlags(): int

Gets the bitmask of the flags used for this CachingIterator instance.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Returns a bitmask of the CachingIterator constants. Use the bitwise & operator to check whether a given flag is set.

Beispiele

Beispiel #1 Checking whether a flag is set

<?php
$iterator = new CachingIterator(
    new ArrayIterator(['a', 'b', 'c']),
    CachingIterator::TOSTRING_USE_KEY | CachingIterator::FULL_CACHE
);

var_dump((bool) ($iterator->getFlags() & CachingIterator::FULL_CACHE));
var_dump((bool) ($iterator->getFlags() & CachingIterator::CALL_TOSTRING));
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

bool(true)
bool(false)

Siehe auch

+add a note

User Contributed Notes 2 notes

up
0
Anonymous
11 years ago
use 'CachingIterator::TOSTRING_USE_INNER' flag

<?php
class A extends ArrayIterator {
    public function __toString(){
        return 'toString this class';
        }
    }

$iterator = new A(array('apple'=>10, 'banana'=>20, 'cat'=>30));
$cache    = new CachingIterator($iterator, CachingIterator::TOSTRING_USE_INNER);

$cache->next();
$cache->next();

echo $cache;

/*
output:
toString this class

*/
?>
up
0
kais7mg at qq dot com
11 years ago
use the 'CachingIterator::TOSTRING_USE_KEY', when echo this Object,
output current 'key';

<?php
$iterator = new ArrayIterator(array('apple'=>10, 'banana'=>20, 'cat'=>30));
$cache    = new CachingIterator($iterator, CachingIterator::TOSTRING_USE_KEY);

$cache->next();
$cache->next();

echo $cache;
?>

output:
banana
To Top