0

I'm having trouble autoloading a class I've written that extends SplEnum. I have successfully installed Spl_Types.

Strangely, the class autoloads fine when run via the CLI. I run into problems when running the scripts through apache, however.

The class is defined as follows:

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

Running this:

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

Gives:

Fatal error: Class 'SplEnum' not found in [...] Colour.php on line 8

I've run phpinfo() through apache and checked that the php.ini file listed includes the spl_types extension, but still no joy.

I'd greatly appreciate any help you could offer with this.

Thanks,

Ross

Ross McFarlane
  • 4,054
  • 4
  • 36
  • 52
  • possible duplicate of: http://stackoverflow.com/questions/6846395/is-it-possible-to-use-splenum-in-php-5-2-6 – marcelog Aug 04 '11 at 18:12
  • This isn't a duplicate of the other issue. As I said above, I have successfully installed SPL_Types, and I'm able to load the class in other circumstances. This problem relates to the differences in autoloading between CLI and Apache. – Ross McFarlane Aug 05 '11 at 10:27

2 Answers2

2

I ran into this same problem, but it seems that a simple service httpd restart was needed.

SPL_TYPES used from https://github.com/davidcoallier/SPL_Types

Compiled with:

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 
1

Have you tried:

class Colour extends \SplEnum {
Martin Gallagher
  • 4,444
  • 2
  • 28
  • 26