Drupal 7's database registry loader does not support indexing or autoloading traits, which were introduced in PHP 5.4. We should support them.

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes
dave reid’s picture

StatusFileSize
new1.69 KB

The last submitted patch, 1: 2508055-autoload-traits.patch, failed testing.

pol’s picture

I'm all for that.

dave reid’s picture

StatusFileSize
new4.04 KB

With a test now.

Status: Needs review » Needs work

The last submitted patch, 5: 2508055-autoload-traits.patch, failed testing.

dave reid’s picture

Status: Needs work » Needs review

Ok! No tests it is! testbot runs on PHP 5.3. :(

pol’s picture

hussainweb’s picture

StatusFileSize
new4.06 KB
new570 bytes

Just a small nit and good for RTBC. The testbot now runs on multiple PHP versions. These changes won't fail on PHP 5.3 once committed. It is the PHP interpreter version used here that causes it to fail. Once the file is in, then the testbot can run on PHP 5.3 as well.

Status: Needs review » Needs work

The last submitted patch, 9: 2508055-autoload-traits-9.patch, failed testing.

hussainweb’s picture

Status: Needs work » Reviewed & tested by the community

Okay, it seems that the testbot changes are only on 8.0.x. Anyway, we could go ahead with patch in #2. Just a small nit:

+++ b/includes/bootstrap.inc
@@ -3108,6 +3111,22 @@ function drupal_autoload_class($class) {
+ * spl_autoload()  handler, and PHP calls it for us when necessary.

Extra space before 'handler'.

hussainweb’s picture

mglaman’s picture

+1. Have to use TravisCI for running tests, can't use D.o

David_Rothstein’s picture

Well we might be able to commit it with the tests (and should if we can) - as far as I can see the testbot only fails because it tries to check the syntax of all files changed by the patch:

[04:13:04] Invoking operation [syntax]...
[04:13:04] Command [php -l -f './includes/bootstrap.inc' 2>&1] succeeded.
[04:13:04] Command [php -l -f './includes/registry.inc' 2>&1] succeeded.
[04:13:04] Command [php -l -f './modules/simpletest/tests/bootstrap.test' 2>&1] succeeded.
[04:13:04] Command [php -l -f './modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test.module' 2>&1] succeeded.
[04:13:04] Command [php -l -f './modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test_trait.inc' 2>&1] failed
  Duration 0 seconds
  Directory [/var/lib/drupaltestbot/sites/default/files/checkout]
  Status [255]
 Output: [PHP Parse error:  syntax error, unexpected T_STRING in ./modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test_trait.inc on line 11

So once this is in core (and no longer being changed by patches) it wouldn't cause tests to fail after that (in theory)... though we'd have to keep a close eye on it afterwards :)

David_Rothstein’s picture

(And the reason it would be nice to is that Drupal 7 should start having multiple-PHP-version testbots in the near future.)

chx’s picture

Status: Reviewed & tested by the community » Needs work

wait a minute if a PHP 5.3 testbot fails on this highly desirable and nice patch then we can't commit it like that cos it'll fail D7 from that point on -- D7 is still 5.2 if I remember correctly. We need to find a way to not autoinclude that file.

David_Rothstein’s picture

Status: Needs work » Needs review

Well the original RTBC was for #2 rather than the latest patch. But see my comment in #14 - I don't think this will fail after commit even though it fails as a patch (but we can't be 100% sure until it's committed)...

I suppose that also means if anyone needs to edit this file later the testbot will fail that followup patch too, so it's a strange situation.

Maybe there is another way to test this instead?

dave reid’s picture

We could commit this without tests, that would work. Otherwise I have no idea how we could get this to pass on the current bot situation and resolve this *now* for Drupal 7 and the people that desire to use traits in modules.

mglaman’s picture

There won't be issues so long as test bot doesn't try to use a Trait. So patch from #2 means I can use traits on projects, or on my TravisCI builds for contributed projects.

David_Rothstein’s picture

Ugh, we can't do what I suggested because https://qa.drupal.org/7.x-status seems to do a PHP syntax check on every single PHP file in core. I thought it only did syntax checks for patched files.

So we may have to go with #2 for now.

Code looks OK but do we need a trait_exists() check in _registry_check_code() to match what's done for classes and interfaces?

Crell’s picture

On behalf of 2008 me, I want to apologize for the existence of this issue. Splitting the autoloader into separate class and interface functions was a stupid idea and I don't know why I even did it. The patch in #2 seems correct, unless we want to fix that mistake and unify the autoloader entirely.

Re #20: If we're keeping the current autoloader design, yes, likely we should add that. Although... since the class/interface already existing should mean the autoloader is never triggered in the first place why do we even have that check...?

David_Rothstein’s picture

StatusFileSize
new4.6 KB
new3.05 KB

Running the tests from #9 locally, they actually failed on PHP 5.4. This fixes that, and also renames the file to hopefully get around the testbot syntax check limitation. (It's really not something the testbot should be doing this aggressively, I think, but the testbots are changing so much these days I'm not even sure filing an issue about it would be relevant - easier to just work around it.)

The file rename using ".php54inc" is a little iffy (and I realized after I wrote it that it also means this won't be blocked by .htaccess so somebody could use this file to flood a PHP < 5.4 site with errors if you wanted to) - maybe it would be better to choose a different extension that .htaccess actually blocks. Currently the testbot does syntax checks on .php/.inc/.install/.module/.test files only, so there's a lot of other extensions that could be used.

Re #20: If we're keeping the current autoloader design, yes, likely we should add that. Although... since the class/interface already existing should mean the autoloader is never triggered in the first place why do we even have that check...?

Hm, good question - offhand I am not sure. Added it in the attached anyway :)

David_Rothstein’s picture

StatusFileSize
new4.57 KB
new1.36 KB

Hey, looks like it worked.

This version switches to a .sh extension which I think is the least unreasonable option of the ones in .htaccess.

Status: Needs review » Needs work

The last submitted patch, 23: 2508055-autoload-traits-23.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Needs review
hussainweb’s picture

Status: Needs review » Reviewed & tested by the community

I think that both methods of masking the file extensions from testbot scanner is a bit iffy, but I think it is fine. Maybe we could add a @todo note in the .sh file to rename this back when the testbot is changed to not check every file in the source. I am thinking this could be done on commit.

hussainweb’s picture

I just tested this on a site with Drupal 7.39. Without the patch, the trait was not found. I applied the patch, reset the registry and it worked fine. It is already RTBC and I am just waiting for it to be committed.

dave reid’s picture

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +7.40 release notes

Committed to 7.x - thanks!

I added a @todo on commit based on @hussainweb's suggestion above, and also created #2589649: Rename drupal_autoload_test_trait.sh to use a standard extension once the testbot allows it:

diff --git a/modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test_trait.sh b/modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test_trait.sh
index 0672172..69ce9ec 100644
--- a/modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test_trait.sh
+++ b/modules/simpletest/tests/drupal_autoload_test/drupal_autoload_test_trait.sh
@@ -6,6 +6,8 @@
  *
  * This file has a non-standard extension to prevent PHP < 5.4 testbots from
  * trying to run a syntax check on it.
+ * @todo Use a standard extension once the testbots allow it. See
+ *   https://www.drupal.org/node/2589649.
  */
 
 /**

  • David_Rothstein committed 183a425 on 7.x
    Issue #2508055 by Dave Reid, David_Rothstein, hussainweb: Add support...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.