Yii Framework Forum: YII_DEBUG false shows PHP notice errors and stops - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

YII_DEBUG false shows PHP notice errors and stops Rate Topic: -----

#1 User is offline   huanito 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 21-November 10

Posted 12 August 2011 - 03:24 PM

Using latest yii-1.1.8.r3324 running with php 5.3.6 on apache 2.2

PHP is set in php.ini to log but not display errors:

display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL | E_STRICT
error_log = /var/www/errors/php-errors

YII_DEBUG and YII_TRACE_LEVEL lines are commented out in index.php so that we are running in Production mode.


Now here's the issue:
When Yii encounters a session_start() call when a session is already started, the app stops and displays:

Error 500
A session had already been started - ignoring session_start()


and then no further page content except the page footer image.

I would have expected that with YII_DEBUG false, as it is by default with the lines in index commented,
that no errors would be displayed and the script would run as normal. Instead the script is balking over a simple notice error which should only be logged.

Looking inside the framework YiiBase.php found the define YII_ENABLE_ERROR_HANDLER
If I define('YII_ENABLE_ERROR_HANDLER',false) in my index file then the errors don't show and the scripts produce normal page content.

But I feel I should not have to do that when YII_DEBUG is defined as false.
Thanks for your comments.
1

#2 User is offline   huanito 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 21-November 10

Posted 09 December 2011 - 04:08 AM

After a server package upgrade on my test system,
one that included upgrade to php 5.3.9, I intentionally set
error_reporting = E_ALL | E_STRICT

per the php.ini instructions to set Development Value: E_ALL | E_STRICT and the error returned.
Not recalling the previous issue, Googled the error and found my own post unanswered <grin />

After much trial and error found that even with these settings in php.ini
display_errors = Off
display_startup_errors = Off
error_log = /var/www/errors/php-errors

Yii still halted as before with error 500 on notice errors like session already started.

Once the error_reporting was set to either
E_ALL & ~E_NOTICE
or
E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

the problem goes away. So there's the workaround in case anyone else runs across this.
0

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,354
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2011 - 04:43 AM

This is not a workaround or a Yii problem... it's how PHP works...

for more info check the PHP documentation - http://php.net/manua...nfiguration.php
Find more about me.... btw. Do you know your WAN IP?
0

#4 User is offline   huanito 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 21-November 10

Posted 13 December 2011 - 08:05 PM

View Postmdomba, on 09 December 2011 - 04:43 AM, said:

This is not a workaround or a Yii problem... it's how PHP works...

for more info check the PHP documentation - http://php.net/manua...nfiguration.php


Thanks for your reply.

I am familiar with that reference and as I read it indicates that the default YII behavior is _not_ how PHP works.

What you say would be the case except for the fact that YII overrides the default PHP error handling behavior in CApplication::initSystemHandlers() like so:
if(YII_ENABLE_ERROR_HANDLER)
set_error_handler(array($this,'handleError'),error_reporting());


By default PHP neither halts for a NOTICE error nor displays it to the user when set in recommended production mode with
error_reporting = E_ALL & ~E_DEPRECATED
and
display_errors = Off

The PHP recommended production error_reporting setting
E_ALL & ~E_DEPRECATED
does not inhibit reporting of NOTICE errors but they are not displayed to the user with display_errors = Off, and scripts are not halted for these type of errors.
When I test outside of YII using simple scripts containing NOTICE errors, those scripts are not halted and no error message is displayed to the user.

However, by contrast, with PHP in recommended production mode, when YII in production mode encounters a simple PHP NOTICE error it both halts (error 500) and displays the NOTICE error.
This is not the default PHP action, i.e., it is not the way PHP works.
0

#5 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 532
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 18 December 2011 - 11:57 PM

Hm... interesting thoughts, but in my oppinion it is better to be forced to write code that does not throw notices...

In most cases when a notice is thrown php does something you would not expect, and shows a notice about what it is doing now, not halting application.

To build a clean good working application you should avoid any notice to prevent unexpected behavior.
1

#6 User is offline   scottix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 16-November 12

Posted 16 November 2012 - 08:50 PM

View PostCeBe, on 18 December 2011 - 11:57 PM, said:

Hm... interesting thoughts, but in my oppinion it is better to be forced to write code that does not throw notices...

In most cases when a notice is thrown php does something you would not expect, and shows a notice about what it is doing now, not halting application.

To build a clean good working application you should avoid any notice to prevent unexpected behavior.


I would like to counter the argument.
There are recoverable and unrecoverable errors.
Example:
$fp = fopen('/some/dir/somefile.txt','w'); // Can throw errors
if($fp === FALSE)
 //dosomething

There could be many reasons why fopen fails and just halting doesn't allow us to deal with it. The only option in this case would be to suppress the errors with '@' which is bad practice and makes bugs even harder to find.

With a standard php program it logs the errors but allows you to continue the program.
Halting can be useful at times but I think halting should be opt-in.
0

#7 User is offline   davidgraybeard 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 13-December 12

Posted 15 May 2013 - 11:16 AM

If anyone finds a workaround for this in Yii that logs the warnings and notices but doesn't halt processing, please post it here. I'll do the same, if I can figure out a way to do it.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users