本文介绍了PHP中是否有静态函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有两个文件在我的许多网页中实现了功能。每个 文件使用名为parseArguments()的函数。这对于每个 两个文件都很重要。 我经常将这两个文件都包含在一个网页中,这会导致名称冲突 for parseArguments()。 我真正想要的是来自C 编程语言的静态函数的概念。静态函数是具有严格文件范围的函数: 没有函数outisde包含模块看到函数。 有没有办法限制联动"只有文件范围的函数? 谢谢! Pete 解决方案 两个parseArguments()函数都做同样的事情吗? Peter Salzman写道:我有两个文件实现我的许多网页中的功能。每个文件使用名为parseArguments()的函数。这对于每个两个文件都是至关重要的。 我经常将这两个文件都包含在一个网页中,这会导致parseArguments()的名称冲突。 /> 我真正想要的是C 编程语言中静态函数的概念。静态函数是一个具有严格文件范围的函数:没有函数outisde包含模块看到函数。 有没有办法限制链接。只有文件范围的函数? 谢谢! Pete Pete, 不,没有像C中那样的静态函数,因为没有像C中那样的单独模块的 概念。 C等价物将是: #include" myfunc1.c" include" myfunc2.c" 会遇到同样的问题。但是在C中你可以编译 " myfunc1"和myfunc2进入不同的模块并具有不同的静态 功能。不幸的是,这个功能在C ++中是不可用的。 你可以做的最好的事情就是设置 " myfunc1.php"作为一个外部程序并调用它 - 但这是很多额外的努力。 如果所有函数和数据都在myfunc1.php中;相关,你可以 创建一个类。与''myfunc2.php'相同。不同的类可以 具有相同的函数名称。如果一个课程不适用,你将有 更改功能名称,因此每个都是唯一的。 - ================== 删除x来自我的电子邮件地址 Jerry Stuckle JDS计算机培训公司 js ******* @ attglobal.net ================== I have two files which implement functionality in many of my web pages. Eachfile uses a function named "parseArguments()" that''s critical for each of thetwo files.I often include both files into one webpage, which results in a name clashfor parseArguments().What I really would like is the concept of static functions from the Cprogramming 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 解决方案 Do both parseArguments() functions do the same thing? 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! PetePete,No, there aren''t any static functions like in C because there isn''t theconcept 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 staticfunctions. 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 ofextra effort.If all the functions and data in "myfunc1.php" are related, you couldcreate a class. The same with ''myfunc2.php". Different classes canhave the same function name. If a class isn''t applicable, you''ll haveto change the function names so each is unique.--==================Remove the "x" from my email addressJerry StuckleJDS Computer Training Corp. js*******@attglobal.net================== 这篇关于PHP中是否有静态函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 14:46