本文整理汇总了PHP中ArrayObject::setIteratorClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayObject::setIteratorClass方法的具体用法?PHP ArrayObject::setIteratorClass怎么用?PHP ArrayObject::setIteratorClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayObject
的用法示例。
在下文中一共展示了ArrayObject::setIteratorClass方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verifyFieldRequirements
/**
* Verify that all required fields are populated
*
* @throws \Genesis\Exceptions\ErrorParameter
*/
protected function verifyFieldRequirements()
{
if (isset($this->requiredFields)) {
$this->requiredFields->setIteratorClass('RecursiveArrayIterator');
$iterator = new \RecursiveIteratorIterator($this->requiredFields->getIterator());
foreach ($iterator as $fieldName) {
if (empty($this->{$fieldName})) {
throw new \Genesis\Exceptions\ErrorParameter(sprintf('Empty (null) required parameter: %s', $fieldName));
}
}
}
}
示例2: array
<?php
// Custom ArrayIterator (inherits from ArrayIterator)
class MyArrayIterator extends ArrayIterator
{
}
// Array of available fruits
$fruits = array("lemons" => 1, "oranges" => 4, "bananas" => 5, "apples" => 10);
$fruitsArrayObject = new ArrayObject($fruits);
// Set the iterator classname to the newly
$fruitsArrayObject->setIteratorClass('MyArrayIterator');
print_r($fruitsArrayObject->getIterator());
示例3: ArrayObject
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
class MyIterator extends ArrayIterator
{
}
$a = new ArrayObject();
$a->foo = "hello";
$a->setIteratorClass('MyIterator');
var_dump($a->foo);
var_dump($a->getIteratorClass());
$ser = unserialize(serialize($a));
var_dump($ser->foo);
var_dump($ser->getIteratorClass());
示例4: setIteratorClass
/**
* @param string $className
*/
public function setIteratorClass($className)
{
$this->data->setIteratorClass($className);
}
示例5: array
<?php
$ar = array(1, 2, array(31, 32, array(331)), 4);
foreach (new RecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator")) as $v) {
echo "{$v}\n";
}
$it = new ArrayObject($ar);
var_dump($it->getIteratorClass());
try {
foreach (new RecursiveIteratorIterator(new ArrayObject($ar)) as $v) {
echo "{$v}\n";
}
} catch (InvalidArgumentException $e) {
echo $e->getMessage() . "\n";
}
echo "===MANUAL===\n";
$it->setIteratorClass("RecursiveArrayIterator");
var_dump($it->getIteratorClass());
foreach (new RecursiveIteratorIterator($it) as $v) {
echo "{$v}\n";
}
?>
===DONE===
示例6: implode
$args = func_get_args();
echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
return parent::current();
}
function next()
{
$args = func_get_args();
echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
return parent::next();
}
function key()
{
$args = func_get_args();
echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
return parent::key();
}
}
$ao = new ArrayObject(array('a' => 1, 'b' => 2, 'c' => 3), 0, "MyIterator");
echo "--> Access using MyIterator:\n";
var_dump($ao->getIteratorClass());
var_dump($ao->getIterator());
foreach ($ao as $key => $value) {
echo " {$key}=>{$value}\n";
}
echo "\n\n--> Access using ArrayIterator:\n";
var_dump($ao->setIteratorClass("ArrayIterator"));
var_dump($ao->getIteratorClass());
var_dump($ao->getIterator());
foreach ($ao as $key => $value) {
echo "{$key}=>{$value}\n";
}
示例7: setIteratorClass
/**
* Implementation of ArrayObject::setIteratorClass().
*
* Sets the classname of the array iterator that is used by ::getIterator().
*
* No value is returned.
*
* @param string $iteratorClass
*/
public function setIteratorClass($iteratorClass)
{
$this->arrayObject->setIteratorClass($iteratorClass);
}
示例8: ArrayObject
<?php
try {
$ao = new ArrayObject(array('a' => 1, 'b' => 2, 'c' => 3));
$ao->setIteratorClass("nonExistentClass");
foreach ($ao as $key => $value) {
echo " {$key}=>{$value}\n";
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
try {
$ao = new ArrayObject(array('a' => 1, 'b' => 2, 'c' => 3));
$ao->setIteratorClass("stdClass");
foreach ($ao as $key => $value) {
echo " {$key}=>{$value}\n";
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
try {
$ao = new ArrayObject(array('a' => 1, 'b' => 2, 'c' => 3), 0, "nonExistentClass");
foreach ($ao as $key => $value) {
echo " {$key}=>{$value}\n";
}
} catch (TypeError $e) {
var_dump($e->getMessage());
}
try {
$ao = new ArrayObject(array('a' => 1, 'b' => 2, 'c' => 3), 0, "stdClass");
foreach ($ao as $key => $value) {