0

我无法自动加载我编写的扩展 SplEnum 的类。我已经成功安装了 Spl_Types。

奇怪的是,当通过 CLI 运行时,类自动加载很好。但是,通过 apache 运行脚本时遇到了问题。

该类定义如下:

<?php
namespace base\main\domain;
use SplEnum;
/**
 * Represents a colour.
 *
 **/
class Colour extends SplEnum {
...

运行这个:

spl_autoload_register(array($autoLoader, 'autoLoad'));
spl_autoload_register('spl_autoload');
$colour = new base\main\domain\Colour(base\main\domain\Colour::BLACK);

给出:

致命错误:在第 8 行的 [...] Colour.php 中找不到类“SplEnum”

我已经运行phpinfo()了 apache 并检查了列出的 php.ini 文件是否包含 spl_types 扩展名,但仍然没有乐趣。

我非常感谢您对此提供的任何帮助。

谢谢,

罗斯

4

2 回答 2

2

我遇到了同样的问题,但似乎需要一个简单service httpd restart的。

从https://github.com/davidcoallier/SPL_Types使用的 SPL_TYPES

编译:

tar xvf SPL_Types-0.3.1.tgz
cd SPL_Types-0.3.1
phpize
./configure
make
make test
make install

echo -e "; Enable spl_types extension module\nextension=spl_types.so" > /etc/php.d/spl_types.ini
service httpd restart 
于 2012-01-07T09:15:01.523 回答
1

你有没有尝试过:

class Colour extends \SplEnum {
于 2011-08-05T10:24:10.370 回答