function scope question

From: Date: Thu, 24 Jan 2002 17:35:14 +0000
Subject: function scope question
Groups: php.general 
Request: Send a blank email to php-general+get-81918@lists.php.net to get a copy of this message
Hello, I wrote a PHP class to display an HTML calendar, and then wrote a subclass of it for a specific project I'm working on. Here is the entirety of the subclass: // create our new sub-class of the calendar class rantCal extends calendar { function get_link($day) { $link = ""; if (valid_date($this->my_year, $this->my_month, $day)) { if (rant_exists($this->my_year, $this->my_month, $day)) { $link = "index.php?date=$this->my_year-$this->my_month-$day"; } } return $link; } } 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. Am I completely wrong? I seem to recall that this sort of thing should work in a more strict OO language, like C++. I'm using PHP 4.0.6, if that's important. -- [ joel boonstra | jboonstra@gospelcom.net ]

« previous php.general (#81918) next »