PHP PEAR Validate Package - Fatal error: Class 'Validate' not found

帅比萌擦擦* 提交于 2019-12-12 23:09:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2186951/php-pear-validate-package-fatal-error-class-validate-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!