tags:

views:

161

answers:

1

This is the error I am receiving:

Fatal error: Class 'Validate' not found in C:\xampp\htdocs\final_project\validate.php on line 5

And here is my PHP code:

 <?php
 require_once 'Validate.php';
 foreach($_POST as $name => $value)
 {
 $valid = Validate::string($value);
 }
 ?>

I do not understand what I am missing. I installed --alldeps for the validate package, and the PEAR include path is also correct. Validate_CA is not giving me any errors, but it is not properly validating either.

+2  A: 

PHP parses the include_path in order of precedence. This means that when a relative path is passed to require(), include(), fopen(), file(), readfile() or file_get_contents(), PHP will start looking in the first directory. If the file is found, it includes it. If not, it will continue to the next and repeats the process.

Consider the following include path:

include_path = ".:/php/includes:/php/pear"

and the following PHP script:

<?php
require('MyFile.php');

PHP will look for MyFile.php in the following order:

  • ./MyFile.php (Current Directory)
  • /php/includes/MyFile.php
  • /php/pear/MyFile.php

The reason why you cannot load Validate.php is you already have a file called validate.php (remember, paths are not case-sensitive on Windows, but are on UNIX) in your current directory. Therefore, PHP includes your file instead of the file corresponding to PEAR::Validate since yours is found before PEAR's in the include_path order of precedence.

Simply renaming your file to something else than validate.php should fix your problem. If it still doesn't work, try echoing the return value of get_include_path() to make sure it really is set right.

Andrew Moore