php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43786 declare() should complain with invalid directive
Submitted: 2008-01-08 12:36 UTC Modified: 2008-01-09 08:39 UTC
From: zabmilenko at charter dot net Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 5.2.5 OS: Any
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: zabmilenko at charter dot net
New email:
PHP Version: OS:

 

 [2008-01-08 12:36 UTC] zabmilenko at charter dot net
Description:
------------
If you use a misspelled or unknown directive in a declare() statement, no error or warning is produced.  To help in debugging, at least a warning should be raised if a directive is used that is not known to the php engine.



Reproduce code:
---------------
<?php
declare(foobar="baz")
{
    echo 'Hello, world';
}
?>

Expected result:
----------------
Perhaps an error or warning stating that the declare directive is unknown or invalid.

Actual result:
--------------
Blocked up code executes like expected but nothing occurs with the declare() statement.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-08 13:25 UTC] zabmilenko at charter dot net
I solved this by adding the following just before line 4705 of ZendEngine2/zend_compile.c (rev 1.796):


// Raise a warning
zend_error(E_COMPILE_WARNING, "Illegal directive [%s]", Z_STRVAL(var->u.constant));


It appears to work on my Debian Etch box, but I don't know if Z_STRVAL is 100% appropriate.  Thanks and have a nice day.
 [2008-01-08 17:53 UTC] johannes@php.net
I think it's intentional. It at lest helps with PHP 6 compatibility :-)

declare(encoding="iso-8859-1");

and such work in PHP 5 and PHP 6 - meaning that PHP 5 ignores it and PHP 6 uses that encoding while parsing the file.
 [2008-01-09 08:31 UTC] zabmilenko at charter dot net
That makes sense.  Would E_STRICT be appropriate in place of E_COMPILE_WARNING then?
 [2008-01-09 08:39 UTC] derick@php.net
No... not at all. It is meant not to show anything because of forwards compatibility between PHP 5.3 and PHP 6.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC