NYCPHP Meetup

NYPHP.org

[nycphp-talk] require[_once]: what the heck?

Allen Shaw ashaw at iifwp.org
Thu Sep 23 09:45:01 EDT 2004


>  > Very annoying gotcha...

Geez, very annyoing indeed!  Good God, how is anybody supposed to figure
that out? [Yeah, I know, read the extended docs, or ask Dan ... :o)  ]

> it may not contain the value you
> expect it to, or it may seg fault your php process.

Yeah, "MAY" -- sometimes maybe yes and sometimes maybe no.  Drat and double
drat!

Anyway, that was the ticket.  Thanks, Dan, for a solution I never would have
guessed.

- Allen


----- Original Message ----- 
From: "Dan Cech" <dcech at phpwerx.net>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Thursday, September 23, 2004 9:26 AM
Subject: Re: [nycphp-talk] require[_once]: what the heck?


> Allen Shaw wrote:
>
> ...snip...
>
> > For context, this code is contained inside of a custom class that's
> > basically adding features to the Smarty engine, and the actual code is:
> >
> > $arReturn = require_once ($this->modulesDir."/".$this->module.".php");
> > or
> > $arReturn = require ($this->modulesDir."/".$this->module.".php");
> >
> > And a typical required file contains:
> > return array ('result',"Completed: $result");
>
> This problem is mentioned in the comments to the php documentation
> (Extended CHM Edition).  Unfortunately it isn't in the online docs, so I
> have quoted it below:
>
> Dan
>
>  > petej-NO-SPAM-at-shaman-dot-ca (12-Mar-2003 09:50)
>  >
>  > If you use (require|include)[_once], to return values, like so:
>  > . . .
>  > $val = require('foo.php');
>  > . . .
>  > you may encounter problems, including Apache seg faults, when using
> this returned value.  For example, if the aforementioned foo.php looks
> like this:
>  > . . .
>  > return array(1,2,3);
>  > . . .
>  > and you use the $val for something, it may not contain the value you
> expect it to, or it may seg fault your php process.  Regardless of the
> action it causes, you can prevent it by doing this instead:
>  > . . .
>  > $ret = array(1,2,3);
>  > return $ret;
>  > . . .
>  > Very annoying gotcha...
>  >
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org




More information about the talk mailing list