Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
PHP 5.3 introduced namespaces. Drupal 8 will make use of them. Code samples are starting to appear on Drupal.org that include namespace syntax.
CodeFilter chokes on namespace syntax. Specifically, backspaces are simply stripped.
This is not a good situation.
See for example here: http://drupal.org/node/1292720 Under the "getting a context object" section.
The line "use \Drupal\Context\Context" is rendered as "use DrupalContextContext", which is, er, wrong.
I am marking this major as it relates to Drupal.org documentation.
Comment | File | Size | Author |
---|---|---|---|
#2 | codefilter.test.2.patch | 6.5 KB | sun |
Comments
Comment #1
Crell CreditAttribution: Crell commentedBumping to critical, since we're posting more and more namespace-using code into issues and docs pages so this is becoming a larger and larger issue. :-(
Comment #2
sunI'm not able to reproduce this issue in the latest D7 code.
Attached patch adds the first test for Code Filter. (Also added a web test template, but currently unused, please ignore.)
Comment #3
webchickHa. Funny story. TRUE story. :)
This is not a bug in this module at all.
This problem is coming from the http://ca3.php.net/highlight_string function.
This script:
When run in PHP 5.3 returns:
<?php use Drupal\Core\Database\Query\AlterableInterface; ?>
But when run in PHP 5.2 (Drupal.org is running PHP Version 5.2.17) returns:
<?php use DrupalCoreDatabaseQueryAlterableInterface; ?>
I guess it makes sense. Namespaces are a PHP 5.3+ thing.
So the solution is either to write our own version of highlight_string() for PHP 5.2 that interprets namespaces correctly, or upgrade Drupal.org to PHP 5.3.
Comment #4
webchickInquiring about the latter over at #1481162: Update prod to PHP 5.3.
Comment #5
Crell CreditAttribution: Crell commentedOh D'Oh! That's awesome. :-)
I guess this isn't critical then, as the fix is to fix Drupal.org.
Leaving open anyway for now since it's linked from a few places.
Comment #6
cweagansThis is working on d.o now, since #1481162: Update prod to PHP 5.3 is done, so can we call this fixed?