Jump to content

php 4.x call to non-member function


cooldude832

Recommended Posts

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

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...

 

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???

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.