-
Notifications
You must be signed in to change notification settings - Fork 73
Prevent extension of static classes #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,18 @@ | |
|
||
namespace Zend\Stdlib; | ||
|
||
use ScriptFUSION\StaticClass; | ||
use Traversable; | ||
use Zend\Stdlib\ArrayUtils\MergeRemoveKey; | ||
use Zend\Stdlib\ArrayUtils\MergeReplaceKeyInterface; | ||
|
||
/** | ||
* Utility class for testing and manipulation of PHP arrays. | ||
* | ||
* Declared abstract, as we have no need for instantiation. | ||
*/ | ||
abstract class ArrayUtils | ||
final class ArrayUtils | ||
{ | ||
use StaticClass; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the constructor private instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what the trait does. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and it's an additional dependency and autoloaded trait (not to mention all the mess that traits lead to at reflection level) on a very, very core dependency. A private constructor is more expressive than an imported trait in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you not think a trait called static class conveys intent clearer than an anonymous private constructor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0xPaul you are indeed correct that A private constructor does convey that immediately, but indeed does not express what the meaning is (although developers usually understand that immediately). |
||
|
||
/** | ||
* Compatibility Flag for ArrayUtils::filter | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,16 @@ | |
namespace Zend\Stdlib; | ||
|
||
use ErrorException; | ||
use ScriptFUSION\StaticClass; | ||
|
||
/** | ||
* ErrorHandler that can be used to catch internal PHP errors | ||
* and convert to an ErrorException instance. | ||
*/ | ||
abstract class ErrorHandler | ||
final class ErrorHandler | ||
{ | ||
use StaticClass; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the constructor private instead |
||
|
||
/** | ||
* Active stack | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,15 @@ | |
|
||
namespace Zend\Stdlib; | ||
|
||
use ScriptFUSION\StaticClass; | ||
|
||
/** | ||
* Wrapper for glob with fallback if GLOB_BRACE is not available. | ||
*/ | ||
abstract class Glob | ||
final class Glob | ||
{ | ||
use StaticClass; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the constructor private instead |
||
|
||
/**#@+ | ||
* Glob constants. | ||
*/ | ||
|
@@ -53,7 +57,7 @@ public static function glob($pattern, $flags = 0, $forceFallback = false) | |
* @return array | ||
* @throws Exception\RuntimeException | ||
*/ | ||
protected static function systemGlob($pattern, $flags) | ||
private static function systemGlob($pattern, $flags) | ||
{ | ||
if ($flags) { | ||
$flagMap = [ | ||
|
@@ -94,7 +98,7 @@ protected static function systemGlob($pattern, $flags) | |
* @return array | ||
* @throws Exception\RuntimeException | ||
*/ | ||
protected static function fallbackGlob($pattern, $flags) | ||
private static function fallbackGlob($pattern, $flags) | ||
{ | ||
if (! $flags & self::GLOB_BRACE) { | ||
return static::systemGlob($pattern, $flags); | ||
|
@@ -175,7 +179,7 @@ protected static function fallbackGlob($pattern, $flags) | |
* @param int $flags | ||
* @return int|null | ||
*/ | ||
protected static function nextBraceSub($pattern, $begin, $flags) | ||
private static function nextBraceSub($pattern, $begin, $flags) | ||
{ | ||
$length = strlen($pattern); | ||
$depth = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,29 +9,30 @@ | |
|
||
namespace Zend\Stdlib; | ||
|
||
use ScriptFUSION\StaticClass; | ||
use Zend\Stdlib\StringWrapper\StringWrapperInterface; | ||
|
||
/** | ||
* Utility class for handling strings of different character encodings | ||
* using available PHP extensions. | ||
* | ||
* Declared abstract, as we have no need for instantiation. | ||
*/ | ||
abstract class StringUtils | ||
final class StringUtils | ||
{ | ||
use StaticClass; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the constructor private instead |
||
|
||
/** | ||
* Ordered list of registered string wrapper instances | ||
* | ||
* @var StringWrapperInterface[] | ||
*/ | ||
protected static $wrapperRegistry = null; | ||
private static $wrapperRegistry = null; | ||
|
||
/** | ||
* A list of known single-byte character encodings (upper-case) | ||
* | ||
* @var string[] | ||
*/ | ||
protected static $singleByteEncodings = [ | ||
private static $singleByteEncodings = [ | ||
'ASCII', '7BIT', '8BIT', | ||
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5', | ||
'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', | ||
|
@@ -45,7 +46,7 @@ abstract class StringUtils | |
* | ||
* @var bool | ||
**/ | ||
protected static $hasPcreUnicodeSupport = null; | ||
private static $hasPcreUnicodeSupport = null; | ||
|
||
/** | ||
* Get registered wrapper classes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependency is to be avoided for this very internal use-case
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, however the dependency only does exactly what this use-case requires and prevents code duplication, and nothing more, thus I think it is appropriate. Moreover, one might opine it reads more intuitively than writing a private constructor by conveying to the reader that the class is static, without need for additional commentary or documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that's not going to happen due to two reasons:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StaticClass
is tagged as 1.0.0 (stable). If this is not good enough what else do you need?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius If you're not going to respond to these points and flatly refuse to use
StaticClass
you can close this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, having a common package is useful here, and I even wrote one myself ( https://github.com/Roave/Dont ), and yes, it also uses traits.
Yes, that's still very tiny, and a non-functional change too. Better than a static reference to an external symbol, and an additional autoloading requirement.
Adding a dependency just for this, where the dependency has a stability and maintenance guarantees lower than the ones in the framework (with all good intent and faith, it's a package maintained by a single developer, and not by the framework team) is a problem.
This is especially true when the package is at the top of the hierarchy (
zend-stdlib
is used everywhere).Please don't take this as mistrust, I'm just telling you that the implications are bigger than the gains, and that by a lot.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy it to your don't package, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do, but won't suggest roave/dont for inclusion here either