Created
June 30, 2017 07:02
-
-
Save patrickallaert/0f0f32135d47ae6459d0bb60327e6d18 to your computer and use it in GitHub Desktop.
Readability poll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Performance appart, what is the most *READABLE* code to generate a simple error string? | |
$errorMessage = "Rule execution failed: " . $e->getMessage(); // Choice 1 | |
$errorMessage = "Rule execution failed: {$e->getMessage()}"; // Choice 2 | |
$errorMessage = sprintf('Rule execution failed: %s', $e->getMessage()); // Choice 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the actual context matters. Where will this message be displayed. How many variables. Is formatting needed.
I personally use
sprintf()
without the variable reusing feature, because this harms readability, is confusing and easily leads to misplaced values when changing the text. So I repeat arguments, if needed.BTW: The PhpStorm plugin PHP Inspections (EA Extended) by @kalessil warns, if there is an argument count mismatch when using
printf, sprintf, fprintf, sscanf, fscanf
. So no direct relation of % to argument, but at least a helpful warning.