RE: [PHP] Error message trying to include a file

From: Date: Tue, 02 Dec 2003 10:28:14 +0000
Subject: RE: [PHP] Error message trying to include a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-171556@lists.php.net to get a copy of this message
On maandag 1 december 2003 23:17 Curt Zirzow told the butterflies: > * Thus wrote Matthias Wulkow (elektrik@gmx.net): > > > > I have an array filled with urls of javascript files and then I > > include them one by one in a loop. > > > > for( $i = 0 ; $i < sizeof($this->page->javascript) ; $i++ ){ > > > > include($this->page->javascript[$i]); > > //This line above is line 52 shown on error warning } > > what does print_r($this->page->javascript) yield? > > you'd be better off with a loop like: > foreach($this->page->javascript as $file_to_include) { > include($file_to_include); } > > > > Curt > -- > If eval() is the answer, you're almost certainly asking the > wrong question. -- Rasmus Lerdorf, BDFL of PHP Probably include($this->page->javascript[$i]); Is the problem. There's this thing in PHP that you can't do this thing with referencing to an object property from within an other object. Or whatever to call that. Sounds silly and stupid, but it bullies me too. Try this: $Page =& $this->page; foreach($Page->javascript as $File) include($File); or this (if you care about memory usage): $Page =& $this->page; foreach(array_keys($Page->javascript) as $i) include($Page->javascript[$i]); Because php doesn't do reference thingies in a foreach loop, sadly. Wouter -note that you do not need { and } for oneline if/foreach/for/while/.. blocks

« previous php.general (#171556) next »