NYCPHP Meetup

NYPHP.org

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

Dan Cech dcech at phpwerx.net
Thu Sep 23 09:26:36 EDT 2004


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...
 >



More information about the talk mailing list