Skip to content

Captcha class harder to extend than necessary #479

@zyspec

Description

@zyspec

Extending the XoopsCaptcha class requires the getInstance() method be overloaded since the method is static and uses CLASS instead of using get_called_class(). If a new class extends XoopsCaptcha and then attempts to get a new instance, an instance of XoopsCaptcha class is created instead of creating a new instance of the calling class.

    /**
     * Get Instance
     *
     * @return XoopsCaptcha
     */
    static function getInstance()
    {
        static $instance;
        if (!isset($instance)) {
            $class = __CLASS__;
            $instance = new $class();
        }
        return $instance;
    }

need to replace $class = CLASS; with $class = get_called_class();

The same issue exists in Xoops 2.5.x series. Obviously this can be circumvented in the new calling class by overloading the getInstance() method, but it shouldn't have to...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions