PHP PEAR 验证包 - 致命错误:找不到“验证"类 [英] PHP PEAR Validate Package - Fatal error: Class 'Validate' not found

查看:66
本文介绍了PHP PEAR 验证包 - 致命错误:找不到“验证"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我收到的错误:

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

这是我的 PHP 代码:

And here is my PHP code:

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

我不明白我错过了什么.我为validate包安装了--alldeps,PEAR包含路径也是正确的.Validate_CA 没有给我任何错误,但也没有正确验证.

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.

推荐答案

PHP 解析 include_path 按优先顺序排列.这意味着当一个相对路径被传递给 require() 时,include(), fopen(), file()readfile()file_get_contents(),PHP 将开始查找第一个目录.如果找到该文件,则将其包含在内.如果不是,则继续下一个并重复该过程.

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.

考虑以下包含路径:

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

以及以下 PHP 脚本:

and the following PHP script:

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

PHP 将按以下顺序查找 MyFile.php:

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

  • ./MyFile.php(当前目录)
  • /php/includes/MyFile.php
  • /php/pear/MyFile.php
  • ./MyFile.php (Current Directory)
  • /php/includes/MyFile.php
  • /php/pear/MyFile.php

您无法加载 Validate.php 的原因是您已经有一个名为 validate.php 的文件(请记住,Windows 上的路径不区分大小写,但在 UNIX 上)在当前目录中.因此,PHP 包含您的文件,而不是对应于 PEAR::Validate 的文件,因为在 include_path 优先顺序中,您的文件在 PEAR 之前被找到.

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.

只需将文件重命名为 validate.php 以外的其他名称即可解决您的问题.如果还是不行,尝试回显 get_include_path() 的返回值以确保它确实设置正确.

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.

这篇关于PHP PEAR 验证包 - 致命错误:找不到“验证"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆