0

I have a PHP file on my website that is producing errors after upgrading from PHP 5.3 to PHP 5.4. This is the error it produces:

Warning: Creating default object from empty value in (removing this part of the error)/arcade.php on line 60

This is what the code looks like after like 60:

{  
    $this->arcade->version = '';        
  }else
  {
    $this->arcade->version = '3.4.0';       
  } 

I'm assuming it has to do with the blank value there. I researched some similar fixes, but I'm still having trouble figuring out exactly what I should add to the php file to fix it.

Thank you very much for any help ahead of time!

Edit: Here's the rest of the code I'm not sure where it intializes. I'm pretty ignorant of these things.

if ( ! defined( 'IN_IPB' ) )
{
    print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files. <br /> <b>File Version 3.3.0</b>";
    exit();
}


class component_public
{
    var $ipsclass   = '';
    var $arcade     = '';

    function run_component()
    {
       $this->ipsclass->load_language( 'lang_Arcade' );



    if( !$this->ipsclass->cache['arcade_settings']['allow_user_skin'] )
     {  
        if( $this->ipsclass->cache['arcade_settings']['skin'] == 0 ) {
             $this->ipsclass->load_template('skin_Arcade1');
        } 
        if( $this->ipsclass->cache['arcade_settings']['skin'] == 1 ) {
            $this->ipsclass->load_template('skin_Arcade2');     
        }  
        if( $this->ipsclass->cache['arcade_settings']['skin'] == 2 ) {
            $this->ipsclass->load_template('skin_Arcade3');     
        } 
     }else

     if( $this->ipsclass->cache['arcade_settings']['allow_user_skin'] && !$this->ipsclass->member['id'] )
     {  
        if( $this->ipsclass->cache['arcade_settings']['skin'] == 0 ) {
             $this->ipsclass->load_template('skin_Arcade1');
        } 
        if( $this->ipsclass->cache['arcade_settings']['skin'] == 1 ) {
            $this->ipsclass->load_template('skin_Arcade2');     
        }  
        if( $this->ipsclass->cache['arcade_settings']['skin'] == 2 ) {
            $this->ipsclass->load_template('skin_Arcade3');     
        } 
     }else

    if( $this->ipsclass->cache['arcade_settings']['allow_user_skin'] && $this->ipsclass->member['id'] )
      {
        $this->ipsclass->DB->query("SELECT arcade_skin FROM ".$this->ipsclass->vars['sql_tbl_prefix']."members WHERE id=".intval($this->ipsclass->member['id']));
        $this->arcade->lib->user = $this->ipsclass->DB->fetch_row();

        if( $this->arcade->lib->user['arcade_skin'] == 0) {
             $this->ipsclass->load_template('skin_Arcade1');        
        } 
        if( $this->arcade->lib->user['arcade_skin'] == 1) {
            $this->ipsclass->load_template('skin_Arcade2');     
        }  
        if( $this->arcade->lib->user['arcade_skin'] == 2) {
            $this->ipsclass->load_template('skin_Arcade3');     
        } 
     }


     if( !$this->ipsclass->cache['arcade_settings']['build'] )  
      {  
        $this->arcade->version = '';        
      }else
      {
        $this->arcade->version = '3.4.0';       
      } 


        $this->ipsclass->vars['arcade_dir'] = 'arcade';

        $component_copyright = '<div class="copyright" align="center"><a href="http://www.ibparcade.com" style="text-decoration: none;" target="_blank">ibProArcade</a> '.$this->arcade->version.' &copy; '.date('Y').'</div>';

        $this->ipsclass->skin['_wrapper'] = str_replace("<% COPYRIGHT %>", $component_copyright . "<% COPYRIGHT %>", $this->ipsclass->skin['_wrapper']);        


        require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/db/arcade_mysql.php';
        $this->arcade->db = new arcade_db;
        $this->arcade->db->ipsclass =& $this->ipsclass;

        require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/arcadelib.php';
        $this->arcade->lib = new arcadelib;
        $this->arcade->lib->ipsclass =& $this->ipsclass;
        $this->arcade->lib->arcade =& $this->arcade;
        $this->arcade->lib->init();

        require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/scoreboard.php';
        $this->arcade->sb = new scoreboard;
        $this->arcade->sb->ipsclass =& $this->ipsclass;
        $this->arcade->sb->arcade =& $this->arcade;

        require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/arcadeskin.php';
        $this->arcade->skin = new arcadeskin;
        $this->arcade->skin->ipsclass =& $this->ipsclass;
        $this->arcade->skin->arcade =& $this->arcade;

        require_once ROOT_PATH.'sources/api/api_topics_and_posts.php';
        $this->arcade->api = new api_topics_and_posts();
        $this->arcade->api->ipsclass =& $this->ipsclass;



        if( $this->arcade->lib->settings['arcade_status'] )
        {

            $this->arcade->lib->arcade_error( array( LEVEL => 1, MSG => 'arcade_offlinemsg' ) );

        }

        $page = (isset($this->ipsclass->input['p'])) ? $this->ipsclass->txt_alphanumerical_clean( $this->ipsclass->input['p'] ) : 'default';
        $code = (isset($this->ipsclass->input['code'])) ? $this->ipsclass->input['code'] : '';

        // Backwords compatibility with older games
        if( isset($this->ipsclass->input['do']) && ($this->ipsclass->input['do'] == 'newscore') )
        {
            $code = 'newscore';
        }

        if( isset($this->ipsclass->input['do']) && ($this->ipsclass->input['do'] == 'verifyscore') )
        {
            $code = 'verifyscore';
        }

        if( isset($this->ipsclass->input['do']) && ($this->ipsclass->input['do'] == 'savescore') )
        {
            $code = 'savescore';
        }


        $file = ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/page_'.$page.'.php';
        if( file_exists($file) )
        {
            require $file;  
        }
        else
        {
            require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/page_default.php';
        }

        $runme = new arcade_page;
        $runme->ipsclass =& $this->ipsclass;
        $runme->arcade =& $this->arcade;
        $runme->exec_page( $code );
    }

}
Gigan
  • 3
  • 1
  • 4

1 Answers1

0

You got that error if trying to access properties of unexistent objects, like this:

$arcade = null;
$arcade->version = '3.4.0';

In order to fix it, yours $this->arcade property should not be empty.

Upd.

First, remove the line with arcade definition/initialization entirely:

class component_public
{
    var $ipsclass   = '';

    function run_component()
    {
       $this->ipsclass->load_language( 'lang_Arcade' );

Next, add this piece of code:

class SilentAssasin {

    public function __get($property) {
        return $this->{$property} = new static();
    }

}

class component_public extends SilentAssasin
{

instead of this:

class component_public
{

That must fix that creating from empty error.

Ah, forgot to mention... That SilentAssasin is just a name for custom class, you actually can name it anything you like, like PathosErrorSuppressor or OversizedBanHammerForThatStupidError etc.

ankhzet
  • 2,517
  • 1
  • 24
  • 31
  • I'm not sure where it initializes. Can you tell me? I posted the rest of the code of the php file in an edit to the original post. Thanks! – Gigan Sep 08 '15 at 01:30
  • Replacing that with what you suggested produced a new error: Parse error: syntax error, unexpected '(object)' (object) (T_OBJECT_CAST) in /home/(removed)/(removed)/sources/components_public/arcade.php on line 23 – Gigan Sep 08 '15 at 02:38
  • @Gigan, probably, object cast isn't supported by PHP 5.4. Try `var $arcade = new stdClass();` instead. – ankhzet Sep 08 '15 at 02:44
  • Tried it in both PHP 5.4 and 5.6, got this new error both times: Parse error: syntax error, unexpected 'new' (T_NEW) in /home/[removed]/[removed]/sources/components_public/arcade.php on line 23 – Gigan Sep 08 '15 at 03:10
  • Okay, the error message changed from row 60 to 61: **Warning: Creating default object from empty value in /home/removed/removed/sources/components_public/arcade.php on line 61** Here's what that line of code looks like: `$this->arcade->lib->user = $this->ipsclass->DB->fetch_row();` – Gigan Sep 08 '15 at 04:15
  • ah, right, there is a havy usage of that `->{empty}->` "feature"... look at update – ankhzet Sep 08 '15 at 04:27
  • Error message changed to **Warning: Creating default object from empty value in /home/removed/removed/sources/components_public/arcade.php on line 69** That line in notepad for me is `$this->arcade->lib->user = $this->ipsclass->DB->fetch_row();` Thanks for all the effort so far. – Gigan Sep 08 '15 at 05:22
  • It's not actually changed... add `var_dump($this->ipsclass->DB);die();` just before that line and show me what it says – ankhzet Sep 08 '15 at 05:30
  • Putting that before line 69 killed the page and formatting and created a white page with a wall of text. Too much to copy and paste. First of like several hundred lines is `object(db_driver_mysql)#3 (26) { ["connect_failed"]=> int(0) ["cached_fields"]=> array(0) { } ["cached_tables"]=> array(0) { } ["obj"]=> array(14) { ` – Gigan Sep 08 '15 at 06:02
  • and if `var_dump($this->arcade);die();` instead of that? – ankhzet Sep 08 '15 at 06:08
  • It becomes a white page save for `object(stdClass)#13 (0) { }` – Gigan Sep 08 '15 at 06:11
  • and `var_dump($this->arcade->lib);die();` ? – ankhzet Sep 08 '15 at 06:20
  • White screen with just the words NULL. – Gigan Sep 08 '15 at 06:24
  • replace `new static();` with `new SilentAssasin();` and show me the output (change dump line to `var_dump($this->arcade);die();`) – ankhzet Sep 08 '15 at 06:25
  • It's a white page with only `object(stdClass)#13 (0) { }` – Gigan Sep 08 '15 at 06:46
  • that's odd. Did you removed `$this->arcade = new stdClass();` line, as i told previously? just before `$this->ipsclass->load_language( 'lang_Arcade' );` line – ankhzet Sep 08 '15 at 06:49
  • I found it and removed it. It's now a white page plus `object(SilentAssasin)#12 (0) { }` – Gigan Sep 08 '15 at 06:59
  • now remove dump line – ankhzet Sep 08 '15 at 07:02
  • Everything is working correctly now. No error! Thank you! – Gigan Sep 08 '15 at 07:09
  • @Gigan, then replace `new SilentAssasin();` back with `new static();` and mark this answer as accepted =) – ankhzet Sep 08 '15 at 07:12