You are here: Re: Are there static functions in PHP? « PHP Programming Language « IT news, forums, messages
Re: Are there static functions in PHP?

Posted by Jerry Stuckle on 11/15/46 11:26

Peter Salzman wrote:
> I have two files which implement functionality in many of my web pages. Each
> file uses a function named "parseArguments()" that's critical for each of the
> two files.
>
> I often include both files into one webpage, which results in a name clash
> for parseArguments().
>
> What I really would like is the concept of static functions from the C
> programming language. A static function is one that has strict file scope:
> no function outisde the containing module sees the function.
>
> Is there a way to limit the "linkage" of a function to file scope only?
>
> Thanks!
> Pete

Pete,

No, there aren't any static functions like in C because there isn't the
concept of separate modules like in C.

The C equivalent would be:
#include "myfunc1.c"
$include "myfunc2.c"

which would suffer from the same problem. But in C you can compile
"myfunc1" and "myfunc2" into different modules and have different static
functions. Unfortunately, that feature isn't available in C++.
Probably the best you could do to emulate it would be to set up
"myfunc1.php" as an external program and call it - but that's a lot of
extra effort.

If all the functions and data in "myfunc1.php" are related, you could
create a class. The same with 'myfunc2.php". Different classes can
have the same function name. If a class isn't applicable, you'll have
to change the function names so each is unique.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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