Bug #69092 [Com]: Declare Encoding Compile Check Wrong

From: Date: Fri, 20 Feb 2015 16:45:18 +0000
Subject: Bug #69092 [Com]: Declare Encoding Compile Check Wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190852@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69092&edit=1

 ID:                 69092
 Comment by:         ircmaxell@php.net
 Reported by:        ircmaxell@php.net
 Summary:            Declare Encoding Compile Check Wrong
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   All
 PHP Version:        master-Git-2015-02-20 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

Patched implementation for 7:

https://github.com/php/php-src/pull/1107


Previous Comments:
------------------------------------------------------------------------
[2015-02-20 15:34:29] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69092&edit=1


Thread (3 messages)

« previous php.bugs (#190852) next »