Hi Mike,

        I finally got it. Thanks. All I needed to do was just define global
$page_title inside the function to denote that I wanted to use that
variable.

One other quick question, in my original code (per below) the function
create_global() was used to create_globals on demand. But this involved a
lot of jumping, from one function to another just to create the globals on
demand. Is this efficient (more?? less??) compared to just stating global
$page_title inside the function?


Please enlighten me.


-------config-----------
$page_title = "Main Page Title";
--------------------------

-------functions---------
function display_title()
{
        global $page_title;  <<---- This was what I missed
        echo $page_title;
}

function org_display_title_code()  <<--- That was what I used originally
{
        $l_main_title = create_globals( 'page_title' );

        echo 'This is (create global) title1 -> ' . $l_main_title  ;
}

function create_globals( $passed_option )
{
        if ( isset( $GLOBALS[$passed_option] ) )
        {
                return  $GLOBALS[$passed_option];
        }
}

-----------------------

------index.php----------
<?php
        display_title();
?>
------------------------


Cheers,
Mun Heng, Ow
H/M Engineering
Western Digital M'sia 
DID : 03-7870 5168


-----Original Message-----
From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 08, 2003 11:34 PM
To: Ow Mun Heng
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] include/require inside of function


> -----Original Message-----
> From: Ow Mun Heng [mailto:[EMAIL PROTECTED]
> Sent: 08 July 2003 15:53
> 
>       Here's the thing.. I declared $page_title = "My Page Title" in a
> file called config.php which is included in the index.php 
> page. when I tried
> to -> echo $page_title <- Nothing comes out. 
> 
>       If I declared it as global $page_title , then "My Page 
> Title" would
> be echoed out.

And is the assignment in the included file inside a function?  If so, the
usual rules about variables within functions apply.  If not, please post the
relevant code from both files so we can try to figure out your problem.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to