skip to Main Content

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


  1. Chosen as BEST ANSWER

    Ok, you won't believe what was the problem.

    I am used to open and close php file like this

    <?
       ...
    ?>
    

    not

    <?php
    
    ?>
    

    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.


  2. With

    $class_name = "cPath_SEO_URL";
    $test = new $class_name();
    return $test::href();
    

    you’re making a static call on an instance. That doesn’t make sense.
    Instead you’ll want to do

    $class_name = "cPath_SEO_URL";
    return $class_name::href(); 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search