You are here: Re: function using global object in PHP5 failes « PHP Programming Language « IT news, forums, messages
Re: function using global object in PHP5 failes

Posted by Arne Claus on 06/27/05 16:50

> ----- C.php -----
> require_once "B.php";
>
> echo $aObj->some_member; // works
>
> function test() {
> global $aObj;
> echo $aObj->some_member; // does not work "Notice: Trying to get
> property of non-object"
> }

Ok - spotted the problem.
I use a function (which adds the base path to my require_once) for
including files, defined as follows

function require_framework($file) {
global $_BASEPATH; // defined somewhere above
require_once $_BASEPATH.$file;
}

If I do the following in my main file main.php

require_framework("C.php");

the error occures as described. If I include normally like

require_once "C.php";

everything works fine. So the problem occured because I created a
function inside another function with this and thus the global keyword
did not work.
Well ... I wanted to discard that require_framework function anyway ^^

Arne

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация