1.2.895. Overload Existing Names¶
Imported alias have precedence over existing ones, and as such, may replace existing features with unexpected ones.
This example shows how to replace strtolower() with strtoupper() while keeping the main code intact. This might be very confusing code. This behavior is important for backward compatibility, and also to avoid naming conflicts when the coding has been done with a PHP installation which do not have some specific declaration. For example, a source may define an ‘Event’ class, which will be in conflict when the ext/event library is installed.
This feature is also useful to mock some native PHP structures, during tests.
This rule relies on the PDFF configuration to check for external existing structures.
<?php
// Replacing a PHP classic with another one
use function strtoupper as strtolower;
echo strtolower('pHp');
// displays PHP
?>
1.2.895.1. Connex PHP features¶
1.2.895.1.1. Suggestions¶
Use another local name than the general name
Always code in a namespace to avoid conflict
1.2.895.1.2. Specs¶
Short name |
Namespaces/OverloadExistingNames |
Rulesets |
|
Exakat since |
2.4.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |