Bluehost.com Web Hosting $6.95

Error message trying to include a file

This is a discussion on Error message trying to include a file within the PHP General forums, part of the PHP Programming Forums category; Hi php-general, I have an array filled with urls of javascript files and then I include them one by ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2003
Matthias Wulkow
 
Posts: n/a
Default Error message trying to include a file


Hi php-general,

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
}

When I had only two files to include it worked. Now I added a third
and I get following error message:

Notice: Undefined offset: 2 in /usr/local/www/ViewPageClass.php on line 52

Warning: writehead() [function.writehead]:
Failed opening '' for inclusion (include_path='.:/usr/local/lib/php')
in /usr/local/www/ViewPageClass.php on line 52

I don't really know what to do,the function writehead doesn't seem to
exist... the javascript file is
http://pajhome.org.uk/crypt/md5/md5.js. I suppose it's free of
errors...

SvT

--
Who is the ennemy?
Reply With Quote
  #2 (permalink)  
Old 12-01-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] Error message trying to include a file

* 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
Reply With Quote
  #3 (permalink)  
Old 12-02-2003
Wouter Van Vliet
 
Posts: n/a
Default RE: [PHP] Error message trying to include a file

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0