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
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: ircmaxell@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 07:00:02 2026 UTC