phpday 2027 - Call for Papers

CachingIterator::getFlags

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

CachingIterator::getFlags — Retourne les drapeaux utilisés

Description

public function CachingIterator::getFlags(): int

Retourne le masque de bits des drapeaux utilisés pour cette instance de CachingIterator.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Retourne un masque de bits des constantes de CachingIterator. L'opérateur binaire & permet de vérifier si un drapeau donné est défini.

Exemples

Exemple #1 Vérification de la définition d'un drapeau

<?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));
?>

L'exemple ci-dessus va afficher :

bool(true)
bool(false)

Voir aussi

+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