Reply to Re: [PHP] Help with Class

Your name:

Reply:


Posted by Ryan Creaser on 09/09/05 11:33

Ian Barnes wrote:

>Hi Ryan,
>
>I am including a different class.inc.php file each time the foreach loops.
>Each one sits in a different dir. Yes, I do get that error.
>
>My understanding of OOP is that I could null the $sdk variable and re-init
>it when the loop starts again..
>
>
You'd be right if the name of class was unique in each class.inc.php.
However, PHP doesn't allow the same class name to be used more than
once, regardless of the include file it's from. It's the same with
function names. The problem is if php allowed you to have two (or more)
classes with the same name it wouldn't know which one to choose when you
used that name - in your case it is obvious because you want to use the
most recently declared class but php can't be excepected to guess that.

You can, however, do something like:
<?php
class ipbsdk {
...
}

foreach (..) {
$var = new ipbsdk();
}
?>
Which would set $var to a new instance of the class every time you loop.
You could null the variable every time but it's not required.

One solution for you might be to redesign the code so you only need one
ipbsdk class , which could take the path as an argument. This class
could then be repeatedly instantiated with a different path each loop,
something like this:

foreach (...) {
...
$SDK = new ipbsdk($fetchd['path']);
...
}

I think your current strategy will lead to a dead end, unless someone
else can see something I'm missing (which is highly likely!).

Hope this helps a little.

Ryan

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация