You are here: Re: include problem « PHP Programming Language « IT news, forums, messages
Re: include problem

Posted by Rik on 02/06/07 17:06

Gunnar G <debian@comhem.se> wrote:

> Hi.
>
> Now I have this file
>
>
> function A()
> {
> if (file_exists("a/foo.inc") echo "exists";
> include "a/foo.inc";
> ....
> }
>
> function B()
> {
> include "B/foo.inc";
> A();
> }
>
> and I start executing function B()
> and it stops at the include in function A.
> Files a/foo.inc and b/foo,inc contains functions with the same name.
> But If I have read the docs right, a include in a function makes the
> included stuff local to that namespace? But will it still conflict with
> the
> included stuff from B/foo.inc ??


You've misunderstood the previous answer. Functions (so not class methods)
are in the 'global namespace', even if they're declared within functions
or methods..

Test this:
----wrong.php-------
error_reporting(E_ALL);
ini_set('display_errors',true);
class foo{
function bar(){
function baz(){
echo 'baz1';
}
}
function foz(){
function baz(){
echo 'baz2';
}
}
}
foo::bar();
foo::foz();
--------------------
versus:
----right.php-------
error_reporting(E_ALL);
ini_set('display_errors',true);
class foo{
function bar(){
echo 'baz1';
}
}
class foz{
function bar(){
echo 'baz2';
}
}
foo::bar();
foz::bar();
--------------------

The previously posted answers still apply:
1. If they're doing different things, they should be named differently.
2. If they're doing the same thing, use a conditional declaration with
function_exists().
3. If they're totally created on the fly, create an anonymous function
with create_function().

(4. Do not abuse OO for this, it might work but is hardly Good Practise.
You should have a valid reason for going OO.)

--
Rik Wasmus

 

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

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