rhyno Posted February 12, 2008 Share Posted February 12, 2008 Fatal error: Call to a member function on a non-object in /home/..../includes/header.php on line 6 is the result of my code... line 6 looks like this $view=new View(); $view->SetFolderlevel(0); and the setfolderlevel function with in the class looks like this... function SetFolderlevel($newFolderlevel) {$this->folderlevel = new $newFolderlevel;} function GetFolderlevel() { $folderPath =""; for($i=0; $i<$this->folderlevel; $i++) $folderPath .="../"; return $folderPath; } Any ideas on this one? Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/ Share on other sites More sharing options...
toplay Posted February 12, 2008 Share Posted February 12, 2008 Maybe you meant to do: {$this->folderlevel = $newFolderlevel;} Having the "new" in there and the 0 (zero) value you were passing it, was trying to force PHP to create a new class object called 0. i.e. {$this->folderlevel = new 0();} which is not possible/correct. FYI: For your second method (function), you don't need to do a loop when you can use str_repeat(). Example: function GetFolderlevel() { return str_repeat('../', $this->folderlevel); } Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/#findComment-464596 Share on other sites More sharing options...
rhyno Posted February 12, 2008 Author Share Posted February 12, 2008 even with your help I am still getting the Fatal error: Call to a member function on a non-object in /home/chry7248/public_html/staging/includes/header.php on line 6 error message when trying to run the script.... Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/#findComment-464770 Share on other sites More sharing options...
toplay Posted February 12, 2008 Share Posted February 12, 2008 Always post current code (as it really is being executed) and identify line 6. You're obviously not showing us all the code since the part you did post at first belongs inside a class and we don't see the definition of the class. Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/#findComment-465039 Share on other sites More sharing options...
rhyno Posted February 13, 2008 Author Share Posted February 13, 2008 Sorry about that... but I have figured out the issue... Thank you for the reply as it has 'enlightened' me for future posts. Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/#findComment-465884 Share on other sites More sharing options...
aschk Posted February 13, 2008 Share Posted February 13, 2008 You're embedding functions inside functions inside classes. I think you need to rethink what you're doing and why. Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/#findComment-465886 Share on other sites More sharing options...
toplay Posted February 13, 2008 Share Posted February 13, 2008 You're embedding functions inside functions inside classes. I think you need to rethink what you're doing and why. He's not. Look carefully at the starting and closing curly braces. One function is NOT inside the other. Link to comment https://forums.phpfreaks.com/topic/90620-getting-a-new-error-well-new-for-me-p/#findComment-466026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.