cooldude832 Posted July 8, 2008 Share Posted July 8, 2008 I'm writing a class to process a form looks like <?php class register_process{ var $submit = 0; var $email = ""; var $email2 = ""; var $password = ""; var $password2 = ""; var $securityq = ""; var $securitya = ""; var $errors = array(); var $messages = array(); #sets inputs into class function define_inputs(){ $this->email = input_clean($_POST['email']); $this->email2 = input_clean($_POST['email2']); $this->password = input_clean($_POST['password']); $this->password2 = input_clean($_POST['password2']); $this->securityq = input_clean($_POST['secruity_question']); $this->securitya = input_clean($_POST['security_answer']); } #adds errors if needed. function error_report($error,$type){ if($type === 1){ $this->errors[] = $error; } else{ $this->messages[] = $error; } } #runs checks on verious inputs returning errors as needed. function verify_inputs(){ function check_email($email,$email2){ if($email != $email2){ $this->error-report("The two emails provided did not match.",1); $e = 1; } $pattern = "^.+@[^\.].*\.[a-z]{2,}$"; if (!eregi($pattern, $email)){ $this->error_report("The email supplied did not match the criteria for a valid email address (example [email protected])",1); $e = 1; } if($e != 1){ $this->error_report("No email errors.",2); } } function check_password($password,$password2){ if($password != $password2){ $this->error_report("The two passwords provided did not match.",1); $e = 1; } if(strlen($password <5)){ $this->error_report("The password must be at least 5 characters long.",1); $e = 1; } $pattern = "[A-Z0-9]"; if(!eregi($pattern,$password)){ $this->error_report("The password can only contain alphanumeric characters.",1); $e = 1; } if($e != 1){ $this->error_report("No password errors.",2); } } function check_security($q,$a){ $q = "Select QuestionID from `".SQ_TABLE."` Where QuestionID = '".$q."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) == 0){ $this->error_report("Please select a valid security question.",1); $e = 1; } if(strlen($a) < 3){ $this->error_report("Please provide a valid security answer.",1); $e = 1; } if($e != 1){ $this->error_report("No security errors.",2); } } check_email($this->email,$this->email2); check_password($this->password,$this->password2); check_security($this->securityq,$this->securitya); } #displays errors as a list function errors_display(){ echo "<ul class=\"errors\">\n"; foreach($this->errors as $value){ echo "<li>".$value."</li>\n"; } echo "</ul>\n"; } } ?> Having issues on the line <?php $this->error_report("No password errors.",2); ?> It works fine in php 5 but bringing it into a php 4 environment makes it all funny. Can I write a solution that will work on 4 and 5 to achieve what I want? exact error is Fatal error: Call to a member function on a non-object on line 41 the line number always corresponds to any $this->error_report() Link to comment https://forums.phpfreaks.com/topic/113682-php-4x-call-to-non-member-function/ Share on other sites More sharing options...
redbullmarky Posted July 8, 2008 Share Posted July 8, 2008 if line 41 is this: $this->error-report("The two emails provided did not match.",1); then i'd suggest changing error-report to error_report doesn't explain why it works on PHP5 though, unless you're testing it in a different way... Link to comment https://forums.phpfreaks.com/topic/113682-php-4x-call-to-non-member-function/#findComment-584260 Share on other sites More sharing options...
cooldude832 Posted July 8, 2008 Author Share Posted July 8, 2008 Nope still errors but that was a mistake could it be because I'm calling it so deep in <?php class{ function error_report(){ } function verify_inputs(){ function check_email(){ $this->error_report("message",1); } } } ?> because its in a function in a function of the class it isn't finding it properly??? Link to comment https://forums.phpfreaks.com/topic/113682-php-4x-call-to-non-member-function/#findComment-584506 Share on other sites More sharing options...
cooldude832 Posted July 8, 2008 Author Share Posted July 8, 2008 its as I expected I migrated all the check_email, check_password etc. outside of hte verify_inputs function and the $this->error_report() works now Any way to do what I wanted and not get that context error Link to comment https://forums.phpfreaks.com/topic/113682-php-4x-call-to-non-member-function/#findComment-584511 Share on other sites More sharing options...
trq Posted July 8, 2008 Share Posted July 8, 2008 Any way to do what I wanted and not get that context error Why do you want functions within functions within a class? Link to comment https://forums.phpfreaks.com/topic/113682-php-4x-call-to-non-member-function/#findComment-584526 Share on other sites More sharing options...
cooldude832 Posted July 8, 2008 Author Share Posted July 8, 2008 I was trying out something so I could verify all my inputs from a single call, but technical I could still do it without burying like I did. I wanted individual functions for each input "type" so that I could adjust them quickly as needed cause the specs aren't determined for them yet. Link to comment https://forums.phpfreaks.com/topic/113682-php-4x-call-to-non-member-function/#findComment-584530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.