I want to create wrapper class, which will enable keys duplicates while default hash does not allow it. Class should use member overloading mechanism introduced in php5, so it would imitate all the behavior standard hash has. For example, I want to have smth like
$var => obj( :values_arr -> array(
obj(:key -> 'mykey', :value -> '...
I wanted to experiment with the Shakespeare programming language, so I downloaded it from here and executed the Makefile using cd spl-1.2.1 Make.
The compilation of spl2c executes with a couple warnings:
scanner.l:600: warning, rule cannot be matched
<stdout>:5808: warning: ‘yyunput’ defined but not used
And then when it at...
What is wrong in my code:
$i = new RegexIterator(
new ArrayIterator(array(
'test1'=>'test888',
'test2'=>'what?',
'test3'=>'test999')),
'/^test(.*)/',
RegexIterator::REPLACE);
foreach ($i as $name=>$value)
echo $name . '=>' . $value . "\n";
The iterator is empty, why? Thanks for your help!
...
I'm pretty green at all the new features implemented with the PHP SPL, from this very long list all I've played with was with the RecursiveDirectoryIterator class, I don't even fully understand it I just saw an example and hacked my way through it.
I've come to love the PHP documentation, but the lack of documentation on these new and s...
I wrote a script that is using the FilterIterator class that comes from the Standard PHP Library (SPL) and I get different behabours accross PHP 5.x versions :( Here the accept() function:
public function accept()
{
$current = $this->current();
print_r($current);
return true;
}
and heres its output for PHP 5.3.1:
Dir...
I am working on an Iphone app which records the sound pressure level in decibels on the headset speakers of a user. Can anyone guide me how to do this? I am not getting the exact functions to refer to so as to achieve this task.
Thanks
Ronny
...
Hi
I have an abstract syntax tree which I need to iterate. The AST is generated by the lemon port to PHP.
Now "normally", I'd do it with the brand new and shiny (PHP 5.3.1) SPL classes, and it would look like this:
$it = new \RecursiveIteratorIterator(
new \RecursiveArrayIterator($ast['rule']),
\RecursiveIteratorIterator::SELF_FI...
In the following code, what can be called instead of ->getFilename()?
<?php
foreach (new DirectoryIterator('../moodle') as $fileInfo) {
if($fileInfo->isDot()) continue;
echo $fileInfo->getFilename() . "<br>\n";
}
?>
PS, I have seen the documentation. Please don't link to here.
Thanks for the help.
EDIT:
After posting thi...
In recent updates to PHP, they added in various interfaces to allow an object to be treated as an array, such as ArrayAccess, Iterator, Countable, etc.
My question is, would it then make sense that the following should work:
function useArray(array $array)
{
print_r($array);
}
useArray(new ArrayObj(array(1,2,3,4,5));
As of righ...
Which PHP SPL interface allows objects to do this:
$object->month = 'january';
echo $object['month']; // january
$record['day'] = 'saturday';
echo $record->day; // saturday
e.g. such as in libraries like Doctrine (Doctrine_Record)
how do I implement this? I've tried using ArrayObject, but they don't behave as I thought they would.
...
I'm trying to extend the SPL ArrayObject but I've hit a little snag. Using an unmodified ArrayObject, this code works:
$a = new ArrayObject();
$a[1][2] = 'abc';
print_r($a);
yielding this output:
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[1] => Array
(
[...
where can i get some references about SPL predefined constants like SELF_FIRST,CHILD_FIRST ? on php.net i don't get much(just their type).
...
how can i retrieve the full directory tree using SPL ?
...
Is it possible to "peek ahead" while iterating an array in PHP 5.2? For example, I often use foreach to manipulate data from an array:
foreach($array as $object) {
// do something
}
But I often need to peek at the next element while going through the array. I know I could use a for loop and reference the next item by it's index ($ar...
$arrayIter = new ArrayIterator( array(1, 2) );
$iterIter = new IteratorIterator($arrayIter);
var_dump($iterIter->valid()); //false
var_dump($arrayIter->valid()); //true
If I first call $iterIter->rewind(), then $iterIter->valid() is true. I'm curious why it requires that rewind() be called. I imagine there's good reason for it, but I ...
I am trying to set a custom class to an Iterator through the setInfoClass method:
Use this method to set a custom class which will be used when getFileInfo and getPathInfo are called. The class name passed to this method must be derived from SplFileInfo.
My class is like this (simplified example):
class MyFileInfo extends SplFile...
I've tried using nested sets, and they become very difficult to maintain when dealing with multiple trees and lots of other complications.. I'd like to give PHP's SPL library a stab at this (btw, we are PHP 5.3, MySQL 5.1).
Given two datasets:
The Groups:
+-------+--------+---------------------+---------------+
| id | parent | Cate...
There are tons of examples of using the RecursiveIterator to flatten a tree structure.. but what about using it to explode a tree structure?
Is there an elegant way to use this, or some other SPL library to recursively build a tree (read: turn a flat array into array of arbitrary depth) given a table like this:
SELECT id, parent_id, na...
Hi everybody.
I've a Store Procedure Routine. I want to get some variables from the execution of that proc.
But i don't know how to create it. For example:
CREATE PROCEDURE foo()
...
RETURN somebar;
END PROCEDURE;
then, when i call it:
-- DEFINE bar, this is what i want to know!!!!
execute procedure foo() into bar;
How can i initial...
I'm playing around with the SPL autoload functionality and seem to be missing something important as I am currently unable to get it to work. Here is the snippet I am currently using:
// ROOT_DIRECTORY translates to /home/someuser/public_html/subdomains/test
define('ROOT_DIRECTORY', realpath(dirname(__FILE__)));
define('INCLUDE_DIRECTOR...