After #334024: Use const keyword to define constants instead of define() was applied trying to install Drupal on PHP <5.x results in an E_PARSE error when trying. This isn't a huge issue as Drupal won't run at all, but instead of giving the readable error when trying to install it just hard crashes with a syntax error.

The const in install.php should be reverted to define() so you at least get the proper error message when trying to access core/install.php.

Any page request besides core/install.php will still result in an E_PARSE, but people might expect that as they haven't finished the install yet. Might have to update some docs to at least warn about this, the core INSTALL.txt at least doesn't mention going to core/install.php just the root directory.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Status: Needs review » Needs work

Sounds good. That would need a comment in the PHPDoc, though, explaining why we use define here, when we use const everywhere else.

Kjartan’s picture

Status: Needs work » Needs review
FileSize
875 bytes

Added a comment. Rest should be the same.

tstoeckler’s picture

Status: Needs review » Needs work
+++ b/core/install.php
@@ -15,8 +15,9 @@ define('DRUPAL_ROOT', getcwd());
+ * Use define() so PHP <5.3 can parse this file and display requirements.

There needs to be a blank line before this. Also I think the comment could be more clear. Maybe: "Use define() so that on PHP versions before 5.3 the installer can display a proper warning instead of a blank page because of a fatal error."
That's actually too verbose, I think, so if you could come up with a shorter version, that would be even better. :)

0 days to next Drupal core point release.

Kjartan’s picture

Status: Needs work » Needs review
FileSize
939 bytes

- Tweaked comment wording.
- Conforming to coding standards.

Status: Needs review » Needs work

The last submitted patch, install_const_to_define-334024-3.patch, failed testing.

Kjartan’s picture

Status: Needs work » Needs review
FileSize
915 bytes

Opps, apparently I screwed up that patch. Trying again.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

yes, simple and awesome patch. RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

To clarify, the intent here is to prevent the installer from crashing before it displays the requirements information.

The patch looks good, but I'd suggest one change:

+++ b/core/install.phpundefined
@@ -16,7 +16,10 @@ define('DRUPAL_ROOT', getcwd());
+// Use define() instead of const so PHP versions older than 5.3 can display the
+// proper PHP requirements.
+define('MAINTENANCE_MODE', 'install');

The two lines of inline comments here should be moved to the docblock (after a blank line). I.e.:

/**
 * Global flag to indicate that site is in installation mode.
 *
 * Use define() instead of const so PHP versions older than 5.3 can display the
 * proper PHP requirements.
 */
xjm’s picture

Oops, xpost.

Kjartan’s picture

Status: Needs work » Needs review
FileSize
952 bytes

Either way works for me.

My reasoning was that the docblock should document the constant and the // comment the special implementation detail as it didn't seem important enough to get dragged into API docs.

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Ah, that's exactly why I thought it should be in the docblock. :) We have additional paragraphs in constant doxygen all over the place, but an inline comment after the docblock isn't a pattern I've seen.

#10 looks good to me.

Anonymous’s picture

yes, simple and awesome patch. RTBC. ;-)

David_Rothstein’s picture

I think I understand Kjartan's reasoning here; this documentation is definitely going to look a little odd at http://api.drupal.org/api/drupal/core--install.php/constant/MAINTENANCE_... the way it is now.

If this were a function, the new sentence would definitely be an inline code comment rather than part of the function's API documentation. However, if we don't do that anywhere else there's probably a good chance that api.drupal.org wouldn't parse it right, so maybe it's not worth experimenting.

To make it a little more clear on a page like that, the beginning of the sentence could be changed to something like "This constant is defined using..." That way someone who comes across it in the API docs will not be confused that the "Use define()..." is some kind of instructions for how they are supposed to use the constant in their own code. It might be worth a quick reroll, but I don't care quite enough to un-RTBC it :)

jbrown’s picture

If the version check goes at the top of the file, can we still have const instead of define?

Kjartan’s picture

No, the order doesn't matter as it results in a E_PARSE, which happens before anything is run. One way to work around it would be to move the const to an include file, but I am assuming there is a reason the const is being set in install.php instead of install.inc (update.php sets it to a different value).

xjm’s picture

FileSize
669 bytes

As usual, David's suggestion makes way too much sense. :) Here's a reroll with that.

Tentatively leaving at RTBC 'cause, yeah. If you think it shouldn't be, please set it back. ;)

jbrown’s picture

What about moving it to core/includes/install.core.inc ?

David_Rothstein’s picture

Moving it to install.core.inc would limit the ability of outside code to use the functions in that file. Granted, most of those functions aren't too useful if you're not in the middle of an installation anyway, but I think it would still be better not to limit it.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed/pushed to 8.x.

Status: Fixed » Closed (fixed)

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

andypost’s picture