MyBB Community Forums

Full Version: Fatal error: Call to a member function getDescription()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I'm working in the next version of my plugin MySEO (GitHub), and in the section plugins, after install the plugin, I see that error:

Fatal error: Call to a member function getDescription() on null in \inc\plugins\myseo.php on line 35


I'm "rewriting" the plugin with a OOP structure, and this function, getDescription(), is in a class in file '/inc/plugins/myseo/core.php', called with a require_once.

Code in myseo.php (plugin file, only until myseo_info() function):
<?php

if (!defined('IN_MYBB')) {
    die('Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.');
}

global $plugins;
$plugins->add_hook('forumdisplay_start', 'myseo_fd');
$plugins->add_hook('index_start', 'myseo_i');
$plugins->add_hook('member_profile_start', 'myseo_mp');
$plugins->add_hook('global_start', 'myseo_ft');
$plugins->add_hook('parse_message_end', 'myseo_nofollow');

function myseo_lang()
{
    global $lang;
    $lang->load('myseo');
}

require_once '/myseo/core.php';
$core = new Core($mybb->settings['bblanguage']);

global $mybb, $core;

function myseo_info()
{

    global $mybb, $plugins, $lang, $db, $core;

    myseo_lang();

    return array(
        'name' => 'MySEO',
        'description' => $core->getDescription(),
        'website' => 'https://github.com/bit-dev/MySEO',
        'author' => 'BitDev',
        'authorsite' => 'https://github.com/bit-dev',
        'version' => '2.0',
        'compatibility' => '18*',
        'guid' => '',
    );
}

Code in core.php (class file, all code):
<?php

class Core{
    private $language;
    private $howToInstall;
    public $description;

    public function __construct($language){
        $this->language = $language;
    }

    private function getLanguageID(){
        if($this->language == 'espanol'){
            return 'es';
        }else{
            return 'en';
        }
    }

    private function languageActions(){
        switch($this->getLanguageID()){
            case 'es':
                $this->howToInstall[0] = "#como-instalar-myseo";
                $this->howToInstall[1] = "#instalar-sistema-nofollow";
                $this->howToInstall[2] = "#install-extras-for-plugin-google-seo";
                break;
            default:
                $this->howToInstall[0] = "#how-to-install-myseo";
                $this->howToInstall[1] = "#install-nofollow-system";
                $this->howToInstall[2] = "#instalar-extras-para-el-plugin-google-seo";
        }

        return $this->howToInstall;
    }

    public function getDescription(){
        global $mybb, $db, $lang;

        $this->description = $lang->pluginDescription.'<br/>';

        $this->description .= '<a target="_blank" href="https://github.com/bit-dev/MySEO/blob/master/README.'.$this->getLanguageID().'.md'.$this->howToInstall[0].'">'.$lang->howToInstall.'</a></span>';
        $this->description .= ' | <a target="_blank" href="index.php?module=config&action=change&search=myseo">'.$lang->settingsLink.'</a> |';

        $this->description .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" style="display: inline;">
            <input type="hidden" name="cmd" value="_s-xclick">
            <input type="hidden" name="hosted_button_id" value="FEC8RBQ2DJUCW">
            <input type="hidden" name="os0" value="Donacion 1">
            <input type="hidden" name="currency_code" value="USD">
            <input type="hidden" name="on0" value="Donaciones">
            <input alt="'.$lang->Cafe.'" title="'.$lang->Cafe.'" style="max-height: 20px; vertical-align: -5px; margin-left: 10px;" type="image" src="'.$mybb->settings['bburl'].'/inc/plugins/myseo/images/donar.'.$this->getLanguageID().'.gif" border="0" name="submit" alt="Donar">
            <img border="0" src="https://www.paypalobjects.com/es_ES/i/scr/pixel.gif" width="1" height="1">
        </form>';

        return $this->description;
    }
}

Before install the plugin, error not appear. The installation actions are executed correctly. I commited the plugin if you need to test the plugin.

Thanks, I wait for your answers. Wink
You're calling to an unexisted method and the way you make your constructors and calling does not exist.

So you have to read about php oriented to objects and learn on how to, really it's very easy and clean way to use on MyBB with newest php versions i remember c programming itself so i think you have no idea on how it works but the best way to learn is reading about it, i make many codes and i know when you learn it you can fo a best job.

But that error is due your code is wrong, so create the method you are trying to call, then use the right way to use it and done.
The error was in variable scope, I declared global $core and all right.


(2016-05-01, 11:54 PM)Dark Neo Wrote: [ -> ]You're calling to an unexisted method and the way you make your constructors and calling does not exist.

So you have to read about php oriented to objects and learn on how to, really it's very easy and clean way to use on MyBB with newest php versions i remember c programming itself so i think you have no idea on how it works but the best way to learn is reading about it, i make many codes and i know when you learn it you can fo a best job.

But that error is due your code is wrong, so create the method you are trying to call, then use the right way to use it and done.
Thanks?