rspec/rules/S1799/php/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

56 lines
1.4 KiB
Plaintext

== Why is this an issue?
The ``++exit(...)++`` and ``++die(...)++`` statements should absolutely not be used in Web PHP pages as this might lead to a very bad user experience. In such case, the end user might have the feeling that the web site is down or has encountered a fatal error.
But of course PHP can also be used to develop command line application and in such case use of ``++exit(...)++`` or ``++die(...)++`` statement can be justified but must remain limited and not spread all over the application. We expect exceptions to be used to handle errors and those exceptions should be caught just before leaving the application to specify the exit code with help of ``++exit(...)++`` or ``++die(...)++`` statements.
=== Noncompliant code example
[source,php]
----
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
----
=== Compliant solution
[source,php]
----
class Foo {
public function bar($param) {
if ($param === 42) {
throw new Exception('Value 42 is not expected.');
}
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this ["exit()"|"die()"] call or ensure it is really required
'''
== Comments And Links
(visible only on this page)
=== relates to: S1147
endif::env-github,rspecator-view[]