venturemc Posted September 16, 2009 Share Posted September 16, 2009 I'm back again...making slow progress on my class building experience, but everything seems very painful in PHP... Keep getting the fatal error when I try to call a function from a class to another class. The identical syntax is working on a previous line in the class. There's a lot of code in this process; I'll try to post just enough... main class <?php class declaration { ...... include_once 'wp_form.cls.php'; // triple+ checked class spelling and path etc ........ private $wpform; private $method; private $action; ....... function set_method($m){ if (isset($m)){ $this->method = $m; } else{ debug_var('method','->no value for $method in wpc set_method<-', $m); // debug_var is a function I wrote for debugging - not the issue } } function set_action($a){ if (isset($a)){ $this->action = $a; } else{ debug_var('action','->no value for $action in wpc set_action<-', $a); } } function get_form(){ $wpform = new wp_form; //problem is here vvvvvvvv $this->wpform = $this->wpform->get_wp_form($this->method, $this->action, $this->wptable); } ?> wp_form class (entire class) <?php class wp_form{ function get_wp_form($m, $a, $t){ // method, action, table $wpform = '<form method ="' . $m . '" action="'. $a . '">'; $wpform.= $t; $wpform.= '</form>'; return $wpform; } } ?> section of php script that sets the object and calls the function <? php ........... //method $m = 'post'; //action $a = 'addemail.php'; $new_wp->set_method($m); $new_wp->set_action($a); $new_wp->get_form(); ........ ?> $method and $action are setting correctly and $this->wptable is getting populated in an earlier step using similar methodology. I've verified that the object wpform is getting created as well. [/] The syntax I'm using to populate wpform seems like it's more than I need, but it's the only syntax taht has worked in previous similar sections of the same class. I'm sure this is something stupid, but I can't find any syntax issues.[/] PHP 5.3.0 if it matters... (the overall project is to build a dynamic webpage. I know there's probably a thousand scripts out there that already do this, but I'm just busting my own chops here for practice) Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/ Share on other sites More sharing options...
Philip Posted September 16, 2009 Share Posted September 16, 2009 $new_wp isn't an object (at least according to your title). You need to make it one in order to call members on it Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919242 Share on other sites More sharing options...
venturemc Posted September 16, 2009 Author Share Posted September 16, 2009 This isn't creating a new object? $wpform = new wp_form; My debugger says it does. Color me confused...... Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919246 Share on other sites More sharing options...
Philip Posted September 16, 2009 Share Posted September 16, 2009 What about $new_wp? $new_wp->set_method($m); Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919248 Share on other sites More sharing options...
venturemc Posted September 16, 2009 Author Share Posted September 16, 2009 Oh... sorry. That has been set earlier in the script and is successfully interacting with other methods. Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919251 Share on other sites More sharing options...
Philip Posted September 16, 2009 Share Posted September 16, 2009 Okay, so whats the exact error you are getting? Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919253 Share on other sites More sharing options...
venturemc Posted September 16, 2009 Author Share Posted September 16, 2009 Other than editing the path, here it is: b>Fatal error</b>: Call to a member function get_wp_form() on a non-object in <b>path------>\webpage.cls.php</b> on line <b>151</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919256 Share on other sites More sharing options...
Philip Posted September 16, 2009 Share Posted September 16, 2009 Ahh okay I see the problem now, it's with scope. function get_form(){ $wpform = new wp_form; //problem is here vvvvvvvv $this->wpform = $this->wpform->get_wp_form($this->method, $this->action, $this->wptable); } $wpform's scope is local to that function, where as $this->wpform's scope is the class It should read: function get_form(){ $this->wpform = new wp_form; //problem is here vvvvvvvv $this->wpform = $this->wpform->get_wp_form($this->method, $this->action, $this->wptable); } Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919261 Share on other sites More sharing options...
venturemc Posted September 16, 2009 Author Share Posted September 16, 2009 Ah ha! I knew it something stupid. Thanks much! Quote Link to comment https://forums.phpfreaks.com/topic/174396-solved-fatal-error-call-to-member-function-onnon-object/#findComment-919266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.