Ankündigung

Einklappen
Keine Ankündigung bisher.

non object [BEANTWORTET]

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • non object [BEANTWORTET]

    Guten Abennd,

    ich stehe heute ein bisschen auf dem Schlauch und komme deswegen bei folgende(m/r) Fehler/Fehlermeldung nicht weiter.
    Irgendwie will die richtige Lösung nicht aus dem Kopf .

    PHP Fehlermeldung/Notice
    Code:
    Notice: Trying to get property 'all' of non-object in F:\Development\Webentwicklung\xampp\htdocs\dashboard\assets\php_inc\utilities.php on line 8
    
    Notice: Trying to get property 'maintenance_state' of non-object in F:\Development\Webentwicklung\xampp\htdocs\dashboard\assets\php_inc\utilities.php on line 8
    
    Notice: Trying to get property 'index' of non-object in F:\Development\Webentwicklung\xampp\htdocs\dashboard\assets\php_inc\utilities.php on line 12
    
    Notice: Trying to get property 'maintenance_state' of non-object in F:\Development\Webentwicklung\xampp\htdocs\dashboard\assets\php_inc\utilities.php on line 12
    
    Notice: Trying to get property 'state' of non-object in F:\Development\Webentwicklung\xampp\htdocs\dashboard\www\index.php on line 17

    PHP Code
    PHP-Code:
    <?php

        
    class utilities {

            public function 
    maintenance_check($page "all") {
                
    $maintenancejsonString json_decode(htmlspecialchars(__DIR__ "/../DataStorage/maintenance_setting.json"));

                if(
    $maintenancejsonString->{"all"}->{"maintenance_state"} == "activated") {
                     return array(
    'state' => truejsonString => $maintenancejsonString->all);
                }

                 if(
    $maintenancejsonString->$page->{"maintenance_state"} == "activated") {
                     return array(
    'state' => true"jsonString" => $maintenancejsonString->$page);
                }

                return array(
    'state' => false"jsonString" => null);
            }

        }

    ?>
    PHP Code 2
    PHP-Code:
    <?php
        
    /*
         * initialize variables
         */
        
    $pageNameString "index";



        
    /*
         * load utilities
         */
        
    require_once(__DIR__ "/../assets/php_inc/utilities.php");
        
    $utilities = new utilities();

        
    /* check if maintenance mode is activated */
        
    $maintenance $utilities->maintenance_check($pageNameString);
        if(
    $maintenance->state === true) {
            echo 
    '<h1>Test:  <?php $maintenance->jsonString->maintenance_use_redirect_url ?></h1>';
            exit();
        }


    ?>
    Danke schon mal, an alle, die meinen alten Gehirnzellen auf die Sprünge helfen können.

  • #2
    Und hast du schon mal nachgesehen, was denn in $maintenancejsonString drinsteht und wie das aussieht (var_dump)? Weiss doch hier keiner, was in dem JSON drinsteht wo das herkommt, dein Problem ist so nicht nachvollziehbar.
    [I]You know, my wife sometimes looks at me strangely. „Duncan“, she says, „there's more to life than Solaris“. Frankly, it's like she speaks another language. I mean, the words make sense individually, but put them together and it's complete nonsense.[/I]

    Kommentar


    • #3
      Zitat von chorn Beitrag anzeigen
      Und hast du schon mal nachgesehen, was denn in $maintenancejsonString drinsteht und wie das aussieht (var_dump)? Weiss doch hier keiner, was in dem JSON drinsteht wo das herkommt, dein Problem ist so nicht nachvollziehbar.
      Ja, da hätte ich selbst drauf kommen könn.

      Ich habe das ganze nun einmal gemacht und bekomme NULL ausgegeben.
      In der Datei selbst steht aber folgendes:

      Code:
      {
          "all" : {
              "maintenance_state" : "activated",
              "_comment" : "use 'disabled' to deactivate the maintenance mode and 'activated' to activate the maintenance mode",
      
              "maintenance_use_redirect" : "true",
              "maintenance_use_redirect_url" : "https://www.anotherWebsite.com/",
      
              "maintenance_heading" : "some maintenance headline ...",
              "maintenance_description" : "some description here ...",
              "maintenance_background_img" : "testuploade.example.de/fefrer",
      
              "allowedIPAdresses" : ["127.0.0.1", "0.0.0.0"]
          },
      
          "index" : {
              "maintenance_state" : "disabled",
              "_comment" : "use 'disabled' to deactivate the maintenance mode and 'activated' to activate the maintenance mode",
      
              "maintenance_use_redirect" : "true",
              "maintenance_use_redirect_url" : "https://www.anotherWebsite.com/",
      
              "maintenance_heading" : "some maintenance headline ...",
              "maintenance_description" : "some description here ...",
              "maintenance_background_img" : "testuploade.example.de/fefrer",
      
              "allowedIPAdresses" : ["127.0.0.1", "0.0.0.0"]
          },
      
          "articlelist" : {
              "maintenance_state" : "disabled",
              "_comment" : "use 'disabled' to deactivate the maintenance mode and 'activated' to activate the maintenance mode",
      
              "maintenance_use_redirect" : "true",
              "maintenance_use_redirect_url" : "https://www.anotherWebsite.com/",
      
              "maintenance_heading" : "some maintenance headline ...",
              "maintenance_description" : "some description here ...",
              "maintenance_background_img" : "testuploade.example.de/fefrer",
      
              "allowedIPAdresses" : ["127.0.0.1", "0.0.0.0"]
          },
      
          "article" : {
              "maintenance_state" : "disabled",
              "_comment" : "use 'disabled' to deactivate the maintenance mode and 'activated' to activate the maintenance mode",
      
              "maintenance_use_redirect" : "true",
              "maintenance_use_redirect_url" : "https://www.anotherWebsite.com/",
      
              "maintenance_heading" : "some maintenance headline ...",
              "maintenance_description" : "some description here ...",
              "maintenance_background_img" : "testuploade.example.de/fefrer",
      
              "allowedIPAdresses" : ["127.0.0.1", "0.0.0.0"]
          }
      }

      Kommentar


      • #4
        PHP-Code:
        json_decode(htmlspecialchars(__DIR__ "/../DataStorage/maintenance_setting.json")) 
        Das ergibt überhaupt keinen Sinn. Erstens übergibst du einen Dateipfad an json_decode(). Schau mal ins Handbuch, welche Parameter die Funktion erwartet. Und zweitens hat hier htmlspecialchars() überhaupt nichts verloren. Was soll das hier bringen?

        Kommentar


        • #5
          Zitat von hellbringer Beitrag anzeigen
          PHP-Code:
          json_decode(htmlspecialchars(__DIR__ "/../DataStorage/maintenance_setting.json")) 
          Das ergibt überhaupt keinen Sinn. Erstens übergibst du einen Dateipfad an json_decode(). Schau mal ins Handbuch, welche Parameter die Funktion erwartet. Und zweitens hat hier htmlspecialchars() überhaupt nichts verloren. Was soll das hier bringen?
          Natürlich.
          Ein großer Dummheitsfehler von mir. json_decode kann natürlich keine Dateipfade öffnen/lesen.
          Habe jetzt noch ein file_get_contents dazwischen gepackt.
          PHP-Code:
          $maintenancejsonString json_decode(file_get_contents(__DIR__ "/../DataStorage/maintenance_setting.json")); 
          Sollte vielleicht lieber morgen weiter arbeiten .

          Danke für eure schnelle und gute hilfe. schönen Abend noch und einen guten start in die Woche

          Kommentar

          Lädt...
          X