I have a class in php called “SEO_URL”. At a point in that class I have this
$class_name = "cPath_SEO_URL";
return $class_name::href();
and I get
Fatal error: Class 'cPath_SEO_URL' not found in
...includesclassesseo.class.php on line 52
The thing is I have included the class on top of SEO_URL
include_once(/path/to/my/class);
class SEO_URL{
}
and I get that error.
However, when I hard-code the class on top of the class SEO_URL it works. So this works.
class cPath_SEO_URL{
function cPath_SEO_URL(){}
function href() { return "CPathHref"; }
}
class SEO_URL{
...
$class_name = "cPath_SEO_URL";
return $class_name::href();
...
}
and this doesn’t
include_once(/path/to/my/class);
class SEO_URL{
...
$class_name = "cPath_SEO_URL";
return $class_name::href();
...
}
I am trying this in oscommerce.
Why is that?
2
Answers
Ok, you won't believe what was the problem.
I am used to open and close php file like this
not
and the class file was without the
<?php .. ?>
tag but the<? ... ?>
tag. I guess the environment I am working in now wanted the<?php
not the<?
only.It would load the class but it wouldn't interpret it as php.
With
you’re making a static call on an instance. That doesn’t make sense.
Instead you’ll want to do