php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #32545 error control operator on include() supresses Parse Errors
Submitted: 2005-04-02 17:21 UTC Modified: 2005-04-05 14:38 UTC
From: mailfrom-bugs dot php dot net at kopka dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0.3 OS: Gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mailfrom-bugs dot php dot net at kopka dot net
New email:
PHP Version: OS:

 

 [2005-04-02 17:21 UTC] mailfrom-bugs dot php dot net at kopka dot net
Description:
------------
I don't know how to classify this so i leave it to someone who might have a better idea how to deal with this:

BUG DESCRIPTION
===============

@include() supresses all error messages, INCLUDING PARSE ERRORS, in the included script and all descendents.
This also affects __autoload so that there are no warnings whatsoever when something goes wrong.
This makes a script using @include undebugable!


DOCUMENTATION PROBLEM
=====================
http://de2.php.net/manual/en/language.operators.errorcontrol.php states that:
Note:  The "@" error-control operator prefix will not disable messages that are the result of parse errors.

which is clearly wrong (see example).

It also states in the follwing warning:
Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why. 

which also quite misses the current behavior.

It seems to me that the current implementation of the @ operator is to set error_reporting to E_NONE for the evaluation of the following expression This is OK for something like
@list($a, $b, $c) = explode($sep, $string);
where it catches the 'Undefined offset' note. 

I ran into this doing the following:

if (!@include_once($path1.$filename)) {require_once($path2.$filename);}

wondering why the script terminates somewhere silently without giving a notice about a reason.
After some hours of digging i found the error which aborted the script and then traced the missing fatal back to the @include().


FEATURE REQUEST
===============

@ should modify error_reporting only for the current expression, and not globally until the evaluation is complete.

RELATED
=======
Effect is also visible in example of Bug #31736


Reproduce code:
---------------
File include.php
------------------
<?php
@include("included.php");
?>

File included.php
------------------
<?php
[parse error of your choice]
?>


Expected result:
----------------
Parse error: parse error, unexpected [something] in included.php on line 2

Actual result:
--------------
FATAL error message is supressed.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-02 17:38 UTC] mailfrom-bugs dot php dot net at kopka dot net
The @include() also eats error messages for exceptions thrown inside the included file which are not catched later on !

a.php
=====
<?php
class Test_Exception extends Exception {}
try {@include_once("b.php");}
catch (Test_Exception $e) {echo "Test_Exception thrown";}
echo "OK";
?>

b.php
=====
<?php
throw new Exception("something wrong");
?>


Expected result:
----------------
Fatal error: Uncaught exception 'Exception' with message 'something wrong' in b.php:2
Stack trace:
#0 a.php(3): unknown()
#1 a.php(6): include_once('b.php)
#2 {main} thrown in b.php on line 2

Actual result:
--------------
OK
 [2005-04-02 18:05 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

. 
 [2005-04-02 18:22 UTC] mailfrom-bugs dot php dot net at kopka dot net
If the behavior is intended then please make the 

Note:  The "@" error-control operator prefix will not disable messages that are the result of parse errors.

(which is wrong in the case of include) on page http://de2.php.net/manual/en/language.operators.errorcontrol.php
more clear about this.

Thanks for your support.
 [2005-04-05 14:38 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Note removed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 09:02:40 2024 UTC