Questions tagged [spl]

SPL is a collection of PHP interfaces and classes that are meant to solve standard problems. This tag is not to be confused with the [shakespeare-lang] tag for Shakespeare Programming Language

SPL stands for Standard PHP Library. It is a collection of PHP interfaces and classes that are meant to solve standard problems. It contains a large set of predefined iterators, data-structures, interfaces and exceptions that can be used and extended.

Documentation can be found here. It is available by default from PHP 5.0.0 onwards.

365 questions
7
votes
10 answers

How do we get coders to look up existing functions before writing their own?

Why are so many people still writing crappy versions of things in standard libraries? Not to go after PHP developers, but guys go read the PHP SPL
Andrew Clark
  • 1,393
  • 1
  • 9
  • 16
7
votes
4 answers

RuntimeException SplFileInfo::getSize(): stat failed for... Laravel 4 upload image

I work with laravel 4 (last update), I create a form where we could upload an image (logo/avatar). I am on MAC OS, I use sublime Text 3, laravel and MAMP Applications. All my configuration is setting right, no running problems. My probleme is that I…
french_dev
  • 2,117
  • 10
  • 44
  • 85
7
votes
2 answers

PHP, SPL predefined constants

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).
kmunky
  • 15,383
  • 17
  • 53
  • 64
7
votes
2 answers

How to sort an SplFixedArray?

Is there a way to perform sorting on integers or strings in an instance of the SplFixedArray class? Is converting to a PHP's array, sorting, and then converting back being the only option?
Desmond Hume
  • 8,037
  • 14
  • 65
  • 112
7
votes
2 answers

Why can't SplFileInfo be converted to boolean?

One of the limitations of PHP is that objects always evaluate to true. However SplFileinfo (and subclasses such as Symfony's UploadedFile) behave differently: $a = new ArrayIterator(); // or any other class $b = new SplFileInfo(__FILE__); //…
Tamlyn
  • 22,122
  • 12
  • 111
  • 127
7
votes
5 answers

SplObjectStorage doesn't work with String, what to do?

Someone has suggested to e to use SplObjectStorage to keep track of a set of unique things. Great, except it doesn't work with strings. An error says " SplObjectStorage::attach() expects parameter 1 to be object, string given in fback.php on line…
erotsppa
  • 14,248
  • 33
  • 123
  • 181
7
votes
2 answers

Fatal Error RecursiveIteratorIterator not found

As the title says, when I instantiate a class I get this message : Fatal error: Class 'Envato\RecursiveIteratorIterator' not found in C:\Users\rgr\Apache\htdocs\Roland Groza [ 3.0 ]\class\envato\envato.php on line 359 You can view the class here :…
Roland
  • 9,321
  • 17
  • 79
  • 135
7
votes
3 answers

iterator_to_array

DatePeriod is a PHP class for handling recurring dates. It has a very limited number of methods. So when I want to do basic array functions with the recurring dates, I have to copy it to an array with iterator_to_array. Strangely, copying it seems…
dnagirl
  • 20,196
  • 13
  • 80
  • 123
6
votes
1 answer

Using SplObjectStorage as a data map, can you use a mutable array as the data?

In the following code: $storage = new \SplObjectStorage(); $fooA = new \StdClass(); $fooB = new \StdClass(); $storage[$fooA] = 1; $storage[$fooB] = array(); $storage[$fooA] = 2; $storage[$fooB][] = 'test'; I would expect $storage[$fooA] to be 1,…
Joe Lencioni
  • 10,231
  • 18
  • 55
  • 66
6
votes
1 answer

PHP's Iterator class

I am working with PHP's SPL Recursive Iterators, they are rather confusing to me though but I am learning. I am using them in a project where I need to recursively grab all files and exclude folders from my result. I was initially using this…
CodeDevelopr
  • 1,267
  • 3
  • 17
  • 30
6
votes
1 answer

Count elements for objects implementing ArrayAccess using count()?

When a class implements the ArrayAccess interface, it becomes ready to function as an array, complete with OffsetGet, OffsetSet and so on. One thing I didn't see was an implementation for when we want to count() or sizeof() it, which, in my limited…
Felipe
  • 11,557
  • 7
  • 56
  • 103
6
votes
1 answer

Correct way of setting a custom FileInfo class to an Iterator

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…
Gordon
  • 312,688
  • 75
  • 539
  • 559
6
votes
2 answers

How can I retrieve the full directory tree using SPL?

How can I retrieve the full directory tree using SPL, possibly using RecursiveDirectoryIterator and RecursiveIteratorIterator?
kmunky
  • 15,383
  • 17
  • 53
  • 64
6
votes
1 answer

php RecursiveDirectoryIterator: how to exclude directory paths with a dot and double dots?

RecursiveDirectoryIterator seems to give me two different results from my localhost and live server, define ('WEBSITE_DOCROOT', str_replace('\\', '/', dirname(__FILE__)).'/'); print_r(WEBSITE_DOCROOT); // List all the class directories in the…
Run
  • 54,938
  • 169
  • 450
  • 748
6
votes
3 answers

PHP's SPL: Do its interfaces involving arrays cover all array properties?

Would it be possible to write a class that is virtually indistinguishable from an actual PHP array by implementing all the necessary SPL interfaces? Are they missing anything that would be critical? I'd like to build a more advanced Array object,…
Wilco
  • 32,754
  • 49
  • 128
  • 160