muckv Posted October 22, 2008 Share Posted October 22, 2008 Whenever I create an object, I follow the code, It passes on the $folder variable as an argument in the constructor (Working I checked) then it sets the global variable value to the passed on $folder value (working) BUT then when the code goes to the nex called upon function. The global $folder loses it's value and becomes null. Any idea how this is possible class folder{ var $folder; function __construct($folder){ $this->$folder = $folder; } function scan(){ $folders = array(); $resource_path = opendir($folder); while (($filename = readdir($resource_path)) != false) { if (is_dir($filename) && $filename != '.'&& $filename != '..') { $folders[] = $filename; } } closedir($resource_path); return $folders; } } $folder1 = new folder('.'); printf($folder1->scan()); Link to comment https://forums.phpfreaks.com/topic/129556-maybe-something-wrong-with-constructor/ Share on other sites More sharing options...
GKWelding Posted October 22, 2008 Share Posted October 22, 2008 $resource_path = opendir($folder); Should be $resource_path = opendir($this->folder); As you are calling the instance of folder as defined within the current class. Link to comment https://forums.phpfreaks.com/topic/129556-maybe-something-wrong-with-constructor/#findComment-671667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.