Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [inne][PHP]Undefined variable 'object' less - Problem
Forum PHP.pl > Forum > Przedszkole
kriskrkpl
Witam serdecznie wszystkich na forum smile.gif

Potrzebuje pomocy w zloklizowanu błędu.

Używam PHP Storm, który zwraca mi następujący problem:

Undefined variable 'object' less... (Ctrl+F1)
The inspection can produce two types of warnings:
The definition of the variable can not be found anywhere. ("Undefined variable")
There are one or more pathes to rich the line with the variable usage without defining it. ("Variable might have not been defined")
All variables from files that contain 'include' or 'require' are considered as defined if the option "Ignore 'include' and 'require' statements" is disabled. The inspection is enabled for global space by default.

Z kolej przeglądarka zwraca mi problem

Fatal error: Call to a member function isAccessible() on null in /public_html/Core/Base/Front.php on line 359

O to kod tego pliku :

  1.  
  2. ....( Górna część kodu )
  3. public function dispatch($controller, $action, $params, $moduleCall)
  4. {
  5. $request = $this->getRequest();
  6. $this->setHelpersPathBase();
  7. $response = $this->getResponse();
  8.  
  9. if ($this->getRequest()->getQuery("widget")) {
  10. $module = $this->formatNamespaceName($this->getRequest()->getQuery("widget"));
  11. $isAccessible = (strtolower($module) == "widget" ? true : $object = $this->getApplication()->getModules($module) instanceof Module && $object->isAccessible());
  12.  
  13. if (!$isAccessible) {
  14. return NULL;
  15. }
  16.  
  17. $disableOb = $this->getParam("disableOutputBuffering");
  18. $obLevel = ob_get_level();
  19.  
  20. if ($disableOb) {
  21. }
  22.  
  23. $this->getApplication()->getEvent()->trigger("onBeforeDispatch." . $module);
  24.  
  25. try {
  26. echo Action::getInstance()->widget($this->getRequest()->getQuery("widget"), $this->getRequest()->getQuery("options"));
  27. }
  28. catch (\Core\Exception $e) {
  29. $curObLevel = ob_get_level();
  30.  
  31. ........( dalsza część kodu )


W czym leży problem questionmark.gif

Proszę o pomoc
Pyton_000
problem masz tutaj:
  1. $object = $this->getApplication()->getModules($module) instanceof Module && $object->isAccessible())


To zwraca Ci:
  1. $object = ($this->getApplication()->getModules($module) instanceof Module && $object->isAccessible())

czyli do $object jest przypisywany wynik logiczny porównania tego:

  1. $this->getApplication()->getModules($module) instanceof Module && $object->isAccessible()


A że w logicznym warunku nie masz zainicjowanej $object to wywala błąd.

Powinno być tak:
  1. $isAccessible = (strtolower($module) == "widget" ? true : ($object = $this->getApplication()->getModules($module) instanceof Module) && $object->isAccessible());
kriskrkpl
Dziękuje za odpowiedź , teraz mam taki błąd , więc w sumie dalej coś nie tak

Fatal error: Call to a member function isAccessible() on boolean in /public_html/Core/Base/Front.php on line 359
Pyton_000
przesuń nawias z "instanceof Module)" tak: ") instanceof Module"
kriskrkpl
Bardzo Tobie dziękuje Działa ! smile.gif

Jeszcze mam tylko ostatnie pytanie smile.gif

Mam taki kod

  1. ( Górna cześć kodu .....)
  2. public function getClassResources($namespace)
  3. {
  4. if (!$this->modules_methods[$namespace]) {
  5. if (version_compare(PHP_VERSION, "5.2.6") === -1) {
  6. $class = new ReflectionObject($namespace . '\Module');
  7. $classMethods = $class->getMethods();
  8. $methodNames = array();
  9.  
  10. foreach ($classMethods as $method ) {
  11. $this->modules_methods[$namespace][] = $method->getName();
  12. }
  13. }
  14. else {
  15. $this->modules_methods[$namespace] = get_class_methods($namespace . '\Module');
  16. }
  17. }
  18.  
  19. return $this->modules_methods[$namespace];
  20. }
  21.  
  22. protected function _loadConfig($file)
  23. {
  24. if (!file_exists($file)) {
  25. throw new \Core\Exception("Missing file '" . $file . "'!");
  26. }
  27.  
  28. $environment = $this->getEnvironment();
  29. $suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION));
  30.  
  31. switch ($suffix) {
  32. case "ini":
  33. require_once ("Config/Ini.php");
  34. $config = new \Core\Config\Ini($file, $environment);
  35. break;
  36. Reszta kodu.....



Oraz taki błąd

Fatal error: Uncaught exception 'Core\Exception' with message 'Missing file ''!' in /public_html/Core/Base/Init.php:753

Proszę o ostatnią pomoc
Pyton_000
W pliku gdzie wywołujesz _loadConfig() wywołanie tej metody musisz objąć w try{} catch{}
kriskrkpl
Problem dalej występuje w tym pliku w którym podałem kod.

Skrypt zwraca mi taki błąd . Problem leży na pewno w pliku init.php

Fatal error: Uncaught exception 'Core\Exception' with message 'Missing file ''!' in /public_html/Core/Base/Init.php:740 Stack trace: #0 /public_html/Core/Base/Init.php(192): Core\Base\Init->_loadConfig(NULL) #1 /public_html/Core/Base/Init.php(157): Core\Base\Init->setOptions(Array) #2 /public_html/Core/Base/Init.php(114): Core\Base\Init->__construct('production', '/home/klient.dh...', NULL, '/home/klient.dh...') #3 /public_html/index.php(21): Core\Base\Init::getInstance('production', '/home/klient.dh...', NULL, '/home/klient.dh...') #4 {main} thrown in /public_html/Core/Base/Init.php on line 740


To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.