[Xapian-devel] PHP Latest

Sam Liddicott sam at liddicott.com
Thu Apr 20 15:05:57 BST 2006

Daniel Ménard wrote:

> Olly Betts a écrit :
>> This page seems to say there are some reserved variable names ($argc,
>> $argv, $PHP_SELF, $HTTP_*):
>> http://aspn.activestate.com/ASPN/docs/PHP/reserved.html
> I was wrong : PHP declares many variables, depending on how the 
> directive "register_globals" is set up.

register_globals would have been practiced in Ninevah if Jonah had not
got their in time. I believe the hittites and jebusites practiced
The downfall of babylon is similarly attributed - by reliable sources :-)

The more awkward we make it for people who use register_globals the better.

> However, it seems that the page you link is not very up to date : it 
> does not mention many of the variables introduced in php 4.1.
> These pages are probably more accurate :
> http://www.php.net/manual/en/reserved.php
> http://www.php.net/manual/en/reserved.variables.php
>> I've not actually tested if it causes a problem to use them as a
>> parameter name - if it does, we can easily invent a suitable renaming
>> scheme.
> I made a quick test with the following code :
> http://www.bdsp.tm.fr/aed/xapian/reserved.php.txt
> It seems, that while these variables are created by PHP, nothing 
> prevents one to use their name as the name of a function parameter. It 
> can't be considered as "good practice", it is not documented as 
> explicitely allowed, and of course it won't be possible from inside 
> the function to use the global predefined php var,


> but it seems to work (I tested with php versions 4.3.10, 5.0.4 and 
> 5.1.2 under windows and debian).
> Even using "$this" as a parameter name doesn't seem to clash anything !

You can get globals from within a function using the special
$GLOBALS['globalname'] array (for example) to get hold of the global var
$globalname, so we can, surely?


>> But it seems that PHP only accepts a constant for a default parameter
>> value - I can't use new or a variable holding an instance of
>> SwigPlaceHolder.
> If I remember correctly, PHP won't accept any "code" as a default 
> value (even 1+1 is not supported), so I'm afraid you're out of luck...

php 3 used to, I remember whining to Andi Gutmans about it's loss; esp.
as all it takes is a macro to implement it! (php don't do macros anyway).

If we wanted

function blah($a,$b=getDefaultArg(), $c=$a+2) {

we can do

function blah($a,$b=NULL) {
  if (func_get_arg_count()<2) $b=getDefaultArg();
  if (func_get_arg_count()<3) $c=$a+2;

so for swig generated php we may be OK doing this.

>> To some extent at least it probably is, but I think you'd need at
>> least some hand-crafted code to capture the different features.  For the
>> Pythonic iterators we just have fully hand crafted Python code which we
>> get SWIG to insert into its generated file (see python/extra.i).   
> I will have a look.
> Best regards,

More information about the Xapian-devel mailing list