We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Showing PHP Notices in Phalcon

I'm trying to display "PHP Notices" in Phalcon. But its philosophy to disable printing any variables from class methods blocks it. Only one method for now works: "tail -f /var/log/httpd/error.log". That's not very convenient. Is there any way to view those notices other than tailing server error log?



51.2k

Try this:

    ini_set('display_errors', 'On');
    error_reporting(E_ALL);

Then before init the application:

(new \Phalcon\Debug)->listen(); // $debug = new \Phalcon\Debug(); $debug->listen();


2.2k
<?php

try {
//debug
  ini_set('display_errors', "On");
  error_reporting(E_ALL);
  $debug = new Phalcon\Debug();
  $debug->listen();
  $config = new \Phalcon\Config\Adapter\Ini('../app/lib/config/configuration.ini');

This is my first 10lines of code in public/index.php And it doesn't work



51.2k

Remove the

  ini_set('display_errors', "On");
  error_reporting(E_ALL);
  $debug = new Phalcon\Debug();

from try {} catch() {} . Phalcon debug throws exceptions



51.2k
edited May '14

  // the correct way. This should be only on your DEV environment !
  ini_set('display_errors', "On");
  error_reporting(E_ALL);
  $debug = new Phalcon\Debug();
  $debug->listen();

try {
  $config = new \Phalcon\Config\Adapter\Ini('../app/lib/config/configuration.ini');


2.2k

First of all thanks for the tip. When You wrote the correct way, i've noticed that my code cant work properly. But it still doesn't work.



51.2k

It would be helpful if you paste the entire index.php code here. Also, to display php notices,

    ini_set('display_errors', 'On');
    error_reporting(E_ALL);

should be enought.



2.2k
edited May '14
<?php

//debug
ini_set('display_errors', "On");
error_reporting(E_ALL);
$debug = new Phalcon\Debug();
$debug->listen();

try {
  date_default_timezone_set('Europe/Warsaw');
  $config = new \Phalcon\Config\Adapter\Ini('../app/lib/config/configuration.ini');
  $loader = new \Phalcon\Loader();
  $loader->registerDirs(array(
      $config->directories->controllers,
      $config->directories->models,
      $config->directories->lib,
      $config->directories->validation,
      'tcpdf' => '../app/lib/assets/tcpdf/',
  ))->register();
  $di = new \Phalcon\DI\FactoryDefault();
  $di->set('view', function() use ($config) {
    $view = new \Phalcon\Mvc\View();
    $version = new Version($config, TRUE);
    $view->setVar('version', $version->getVersion());
    $view->setViewsDir('../app/views/');
    return $view;
  });
  $di->setShared('session', function() {
    $session = new Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
  });
  $di->set('dispatcher', function() {
    $eventsManager = new \Phalcon\Events\Manager();
    $eventsManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) {
      if ($exception instanceof DispatchException) {
        return false;
      }
      if ($event->getType() == 'beforeException') {
        switch ($exception->getCode()) {
          case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
          case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
            $dispatcher->forward(array(
                'controller' => 'index',
                'action' => 'notExists'
            ));
            return false;
        }
      }
    });
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
  }, true);
  $app = new \Phalcon\Mvc\Application($di);

  echo $app->handle()->getContent();
} catch (\Phalcon\Exception $e) {
  echo '<pre>';
  echo get_class($e), ": ", $e->getMessage(), "<br />";
  echo " File=", $e->getFile(), "<br />";
  echo " Line=", $e->getLine(), "<br />";
  echo " Stack Trace: <br />";
  foreach (explode("#", $e->getTraceAsString()) as $i => $trace) {
    if ($i != 0)
      echo ' #' . $trace;
  }
  echo '</pre>';
}