0

I am trying to upgrade the code of a new project I am working on to comply with PSR-0.

I am using and SPL loader class, However I may be doing something wrong, I just can't spot what the issue is.

I keep getting the following error:

Fatal error: Class 'widezike\General' not found in /nfs/c03/h04/mnt/169128/domains/widezike.com/html/beta/lib/functions.php on line 14

This is my folder structure:

index.php
-lib
config.php
init.php
spl-class-loader.php
functions.php
    -widezike
        -General.php

This is my functions file where it begins anything to do with the server side code:

<?php

include 'init.php';
include 'config.php';

include 'spl-class-loader.php';

$loader = new SplClassLoader('General', 'lib/widezike');
$loader->register();

use widezike\General;

//Run the output buffer
General::ob();

So this is my code for now, but I can't seem to find what's causing the fatal error...

Thanks in advance

6
  • Can you post the error? Commented Jun 5, 2013 at 11:52
  • The error is right at the top, Fatal Error: class 'widezike' etc.... Commented Jun 5, 2013 at 11:53
  • Can we see autoloader itself? Commented Jun 5, 2013 at 11:53
  • I'm using this autoload class unmodified: gist.github.com/jwage/221634 Commented Jun 5, 2013 at 11:54
  • Is spl-class-loader is loaded into the same folder. As you are using the include_once rather require_once() it wont fire any error but there might be a problem. Commented Jun 5, 2013 at 12:08

2 Answers 2

1

I'm taking a bit of a guess here but I think the issue is in the constructor..

$loader = new SplClassLoader('General', 'lib/widezike');

In the code you linked to they are the namespace and the include path.

Play around with those until it works is all I can suggest.

You might try:

$loader = new SplClassLoader(null, 'lib');

Or

$load = new SplClassLoad('General', 'lib');

On the other hand I personally just use a very simple spl_autoload_register function to do my class loading for me..

spl_autoload_register(function($class){

    $filename = str_replace('\\', '/', $class) . '.php';
    require($filename);

});

$object = new phutureproof\common\whatever();

I would then have a file /phutureproof/common/whatever.php with the contents:

<?php
namespace phutureproof\common;

class whatever
{

}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I think it might be a different issue, I tried your auto loader and i get the same kind of issue, somehow i think the PHP isn't seperating out the class name and trying to literally load a class called: widezike\General. Using your method i got this: lib/widezike/general.php Fatal error: Class 'lib\widezike\General' not found in /nfs/c03/h04/mnt/169128/domains/widezike.com/html/beta/lib/functions.php on line 20 I made it print the generated include to make sure that was creating the right thing and it is :S so i'm stumped
are you putting the right namespace in your classes? namespace lib\widezike; class General {}
Well, good luck friend, I can't think of anything else.. hopefully some bright spark will come along and have the answer :)
0

I realised that the issue was that my name spaces were wrong, so if you have the same issue just check and make sure that your namespaces are correct!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.