[Gllug] OTish - Basic? PHP query

Ben Fitzgerald ben_m_f at yahoo.co.uk
Sat Oct 22 17:00:45 UTC 2005


On Sat, Oct 22, 2005 at 03:54:49PM +0100, Dylan wrote:
> Hi All,
> 
> I have a PHP script (index.php) which "include()"s a library script 
> (lib.php) containing a function (extract_macro.) If I call 
> extract_macro($x) from outside any function in index.php, it executes 
> as expected. If, however, I call it from inside a function, it doesn't 
> get executed. I assume it's out of scope, so is there an equivalent of 
> global for functions, or do I need to "include" the script in every 
> function?

doesn't get executed? does it try to run it and error or silently step
over it? the latter would be odd. strace prog.php |grep my_function?

haven't touched php for a while but from the zend web page:

  http://www.zend.com/manual/language.functions.php

  " All functions and classes in PHP have the global scope - they can be
  called outside a function even if they were defined inside and vice
  versa."

Is it possible you are calling your function before your include
statement is executed? Not sure if php scans for include first and reads
in the code + creates user defined functions or if it's done on the fly.

Does this work:

<?php
# quick run function inside another + in main

include("lib.php");

function testme()
{
  echo "running my_function";
  my_function();
}

my_function();

echo "running testme";
testme();

?>

Apologies if the above smacks of me telling you how to suck eggs! :-)

ben.

-- 
Registered Linux user number 339435
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list