PHP Inheritance issue

Hello,

I’m trying to workout an inheritance issue in PHP but its not working as I want, I’m receiving the message: Fatal error: Class ‘ValidateUserInput’ not found in C:\xampp\htdocs\InheritanceTesting\authenticationClass.php on line 2.

  • the files are in the folder.
  • I check a few online tutorial and I still cant seem to pinpoint the error message I’m getting.

Any help you can provide would be greatly appreciated.

index.php
<?php
require_once(‘authenticationClass.php’);
require_once(‘validateClass.php’);

  $classReturn = new Authentication();  

    if(isset($_POST['btl_logIn']) && $_POST['btl_logIn'] == 'Log In'){
         $test1 =  $classReturn->UserAuthentication($_POST['txt_userEmail']);
        if($test1){
            echo 'found';
        }
        else{
            echo 'Not found';
        }         
    }
?>  
<br><br>Inheritance testing<br><br>
<form method="POST" action="" name="loginForm">       
    <div id="loginContainer" style="border: 1px solid green;  float: middle; width:600px;" >
        <input type="text" name="txt_userEmail" placeholder="Email" />         
        <input type="submit"  name="btl_logIn" value="Log In">           
    </div>
</form>

authenticationClass.php

<?php
class Authentication extends ValidateUserInput { 

    public function UserAuthentication($userEmail){      
       if($this->senitizeEmailField($userEmail)){                   
           return TRUE; 
       }
        else{
            return false;
        }
    }
}
?>

validateClass.php

<?php
class ValidateUserInput{

    public function senitizeEmailField($userEmail){
            if (isset($userEmail)) {               
                $pattern = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';     
                if (!preg_match($pattern, $userEmail)) {               
                    return FALSE;
                } 
                else {                   
                    return TRUE;
                }
            }
            else{               
                return FALSE;
            }
    } 
}
?>

Is it something as basic as needing to include them in the opposite order?

require_once('validateClass.php'); 
require_once('authenticationClass.php'); 

so that when you define the Authentication class, ValidateUserInput has already been included in the code?

wow… to simple… tried it and it works… thanks Droopsnoot…

1 Like

If you had used an autoloader, the autoloader would have figured out the order of including itself.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.