Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7467994
StaticInFinalClassStandard.xml
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
StaticInFinalClassStandard.xml
View Options
<?xml version="1.0"?>
<documentation
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
title=
"Static in Final Class"
>
<standard>
<![CDATA[
When a class is declared as final, using the `static` keyword for late static binding is unnecessary and redundant.
This rule also covers using `static` in a comparison with `instanceof`, using `static` for class instantiations or as a return type.
`self` should be used instead.
This applies to final classes, anonymous classes (final by nature) and enums (final by design).
]]>
</standard>
<code_comparison>
<code
title=
"Valid: Using 'self' in a final OO construct."
>
<![CDATA[
final class Foo
{
public function myMethod(
$
param) : <em>self</em>
{
$
var = <em>self</em>::functionCall();
$
var =
$
obj instanceof <em>self</em>;
$
var = new <em>self</em>;
}
}
]]>
</code>
<code
title=
"Invalid: Using 'static' in a final OO construct."
>
<![CDATA[
$
anon = new class {
public function myMethod(
): int|<em>static</em>|false {
$
var = <em>static</em>::
$
prop;
$
var =
$
obj instanceof <em>static</em>;
$
var = new <em>static</em>();
}
};
]]>
</code>
</code_comparison>
</documentation>
File Metadata
Details
Attached
Mime Type
text/xml
Expires
Mon, Nov 23, 06:22 (3 d, 13 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
50/02/1d7de9ef0ccf11e10e6828bebfbd
Default Alt Text
StaticInFinalClassStandard.xml (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment