0

I am using a static factory method to create a concrete implementation of an abstract class. But I am constantly getting the "Class Not Found" error.

I know that my "require" paths are correct because any other configuration leads to the "failed to open stream" error.

My question is, why am I getting this "Class Not Found?"

class A {
   public function method () {
      $obj = B::factorymethod();
   }
}

abstract class B {
   static function factory() {
      return new C();
   }
}

class C extends B {}

When I do this I get:

Fatal error: Class 'B' not found in C:\phpproject\C on line 11

A has require_once(B.php), B has require_once(C.php), C has require_once(B.php)... there are no other errors.

1 Answer 1

2

Because you have used the non-existent keyword method in your code, preventing your class from being properly recognized and evaluated, thus, not being discovered among correctly defined classes.

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

1 Comment

Thanks -- that's not the real name of the method that I was using but some lazy pseudocode. At any rate works now that I've fixed the Abstract Class... I don't have the time to dig into what went wrong here but I think that the retrieval of the Abstract Class was silently failing, because of errors in its design (but not the "method" thing lol). Your point is true though, so while it does not apply to my code it should be seen.

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.