[TYPO3-ect] PHP5, lib/div, ArrayAccess, Iterator, SPL ...

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Mon Jun 18 23:30:15 CEST 2007


How do we get the full SPL / ZEND engine features for PHP5?

Hello,

when I designed lib/div I was thinking of two interesting interfaces of
PHP5 that are defined by the ZEND engine and implemented into SPL objects.
And the switch between PHP4 and PHP5 is indeed minimalistic. Still we need
an automatic switch.

I speak of ArrayAccess and Iterator.

--------------------------------------------
ArrayAccess: 
--------------------------------------------

In PHP4 it works with arrays: 

  $value = $array[7];

In PHP5 it also works with objects that implement the ArrayAccess interface.

  $value = $this[7];

PHP4 workaround:

  $value = $this->get(7);

--------------------------------------------
Iteator:
--------------------------------------------

In PHP4 we can do this with arrays: 

  foreach($array as $key => $value) ....

In PHP5 we can do this with objects that implement the Iterator interface:

  foreach($this as $key => $value) ....

PHP4 workaround:

  for($this->rewind(); $this->valid(); $this->next) {
    $key = $this->key();
    $value = $this->current();
  }

--------------------------------------------
PHP 5 activation:
--------------------------------------------

To activate the PHP5 methods a change of one single line is required, the
class definition of tx_lib_object:

  PHP4: 

class tx_lib_object extends tx_lib_selfAwareness { ...

  PHP5: 

class tx_lib_object extends tx_lib_selfAwareness implements ArrayAccess, Iterator { ... 


Currently I havn't a PHP4 running to test if the change would break PHP4,
but I guess so. Is there somebody reading with PHP4 on board to test it?

If it breaks here is my question to the cracks of you: How could we
implement a switch, so that the interfaces are automatically activated if
PHP5 is running? Is there a smart way to achive this? Best ideas first ...

Regards

Elmar


More information about the TYPO3-team-extension-coordination mailing list