Re: Friend of function??

From: Date: Thu, 19 Sep 2002 02:17:30 +0000
Subject: Re: Friend of function??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-116830@lists.php.net to get a copy of this message
Just as Kevin Stone said, you can either use one of these constructions: function func1() { global $myarray; array_push($myarray,1); } # _or_ function func2() { array_push($GLOBALS['myarray'],1); } In fact, there is no performance decrease, because PHP will internally use the same mechanism to access the array - as it would if you were not in a function. Another way would be to pass the array as a reference: function func3(&$myarray) { array_push($myarray, 1); } but this might decrease performace (in compare to the other ways, you will not really notice it). Sascha Am Mittwoch, 18. September 2002 23:54 schrieb Anup: > I want to use arrays (that are outside of a function) to be visible to a > function. I understand that I must you global. But I was wondering is it > possible to make it visible to only certain functions, similar to the > 'friend' keyword in C (or C++ ?) ? The reason, is that I don't feel > comfortable having globals, (I was brought up that way). Also, if you > actually declare something global are there any disadvantages such as > performance hits?

« previous php.general (#116830) next »