Re: function scope question

From: Date: Thu, 24 Jan 2002 17:42:24 +0000
Subject: Re: function scope question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-81921@lists.php.net to get a copy of this message
Joel- > Basically, it's used to determine if a given date should be linked or not. > When I wrote it, I didn't expect it to work, since these two function: > > valid_date() > rant_exists() > > are defined completely outside of the class. In fact, they're defined in > a functions file that I include (with include()) above where I define my > rantCal class. Shouldn't their names not be recognized within this class? > I was assuming that a class was entirely self-contained, so it can't know > about functions defined outside its scope. However, it works just fine > (that is, the functions get called), which is helpful, but it doesn't seem > like the way things should work. When functions are defined, they are available everywhere: in other functions, in classes, and in subclasses. As far as availability goes, any function you define is just as available as any of the built-in PHP functions (like addslashes() for instance). Personally, though I am not a HEAVY OO programmer, I cannot see why having those functions UNAVAILABLE in the class would be advantageous in anyway. If you want a function to exist ONLY within a particular class, then it should be created in that class, otherwise, it should be created outside of any class, and is therefore available globally. I can't say whether it SHOULD be the way it is or not... but I can tell you that the behaviour you are describing is accurate and intended. Daniel J. Lashua

« previous php.general (#81921) next »