php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69092 Declare Encoding Compile Check Wrong
Submitted: 2015-02-20 15:34 UTC Modified: 2015-02-22 03:01 UTC
From: ircmaxell@php.net Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2015-02-20 (Git) OS: All
Private report: No CVE-ID: None
 [2015-02-20 15:34 UTC] ircmaxell@php.net
Description:
------------
The current compile-time error check for declare(encoding="...") is incorrect.

Declare is a parse-time only directive, which does not respect scope. The current compile-time checks for the declare(encoding) directive only check to see if it's the first opcode in the active oparray.

This is fine if the active oparray is a file, however if it is a function odd behavior will be allowed. In the provided test script, "Bye" would be interpreted using the UTF-8 encoding pragma, where "Hi" would use the default.



Test script:
---------------
<?php

echo "Hi";

function foo() {
    declare(encoding="UTF-8");
}

echo "Bye";

Expected result:
----------------
Fatal error: Encoding declaration pragma must be the very first statement in the script

Actual result:
--------------
HiBye

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-20 16:45 UTC] ircmaxell@php.net
Patched implementation for 7:

https://github.com/php/php-src/pull/1107
 [2015-02-22 03:01 UTC] laruence@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
 [2015-02-22 03:01 UTC] laruence@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 08:01:33 2024 UTC