Your origin code is good.
if (! $this->contractValue) {
return;
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, is there a way to make this shorter?
if ( !$this->contractValue ) {
return;
}
This is what I am trying to write in my head
!$this->contractValue : return ;
so what I want to write is: if contractValue is false null or empty then return
the return is writen because I want the function to stop there and dont keep moving forward in the code all PHP
thanks a lot for your hepl
@arius tigger Good code isn’t the shortest code possible; good code is code that someone can read and instantly work out what it’s doing.
So how would making…
if ( !$this->contractValue ) {
return;
}
…shorter improve it any? I can read it and instantly know what’s going on: it’s an if statement, where if something isn’t true your function/method immediately returns.
Condensing it to a single line using non-traditional syntax isn’t going to make your code any faster, nor any easier to read. It’ll in fact have the opposite effect.
Remember: code is read many more times that it is written. Prefer code that’s easy to read; don’t try to be “clever” and make three lines of code one line for no discernible benefit.
Please or to participate in this conversation.