[TYPO3-core] declare(encoding='UTF-8'); in extension config files

Christian Weiske christian.weiske at netresearch.de
Mon Feb 25 11:01:35 CET 2013


Hello all,



Since PHP 5.3.0, developers may declare the character set of a PHP file
using a declare line at the beginning of a file[1]:

> declare(encoding='ISO-8859-1');
or
> declare(encoding='UTF-8');

This can be used by editors to display the file's characters correctly,
and is used by PHP's zend multi byte feature (--enable-zend-multibyte)
to automatically convert the strings in the file.

A declare(encoding) statement is only valid at the beginning of a file,
and may be used only once - otherwise a fatal error is issued:
> PHP Fatal error:  Encoding declaration pragma must be the very first
> statement in the script

Knowing that behavior is important when merging several PHP files
together. TYPO3 does this when creating temporary files that contain the
contents of ext_tables.php and ext_localconf.php of all active
extensions.

When creating those files, TYPO3 needs to remove those declare encoding
lines, because otherwise the temporary files are invalid and lead to
fatal PHP errors.


We've created a patch for this, http://forge.typo3.org/issues/40069

Helmut Hummel is in favor[2] of simply declaring the declare()
statements as "not allowed" in ext_localconf.php/ext_tables.php files,
thus making the issue a non-issue by ignoring it.

I think that TYPO3 should handle this case: Using declare statements is
allowed in PHP, and useful for both editing tools and and PHP output.

What do you think?


[1] http://php.net/manual/en/control-structures.declare.php
[2] http://forge.typo3.org/issues/40069#note-16

-- 
Regards/Mit freundlichen Grüßen
Christian Weiske

-= Geeking around in the name of science since 1982 =-



More information about the TYPO3-team-core mailing list