Code required for interfaces, Iterator & Countable in ph

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Code required for interfaces, Iterator & Countable in ph

Post by raghavan20 »

we have a live server running with PHP version 5.0.4 but we have a latest version running in our test server. I managed to use a Zend module from Zend framework in test server but it throws error as it could not find Countable.php and Iterator.php. I am wondering whether I would be able to get actual php code for these two files.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

You can create those interfaces but it won't help. Countable will let you do this

Code: Select all

class myClass implements Countable
{
  public function count() { ... }
}

$instance = new myClass() ;
count($instance) ;

That will fail under php 5.04 even if you do recreate the countable interface. Same thing will happen with the Iterator interface. As soon as you try to use your object in a foreach loop it will fail. Your only solution is to not use SPL or to upgrade the live server.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

i did create Countable and Iterator interfaces from the api provided. It did work. These interfaces are required by Zend_Config. anyway, thanks for your help.
Post Reply