0
Answered

INTRODUCE NULL OBJECT

Abelardo LeΓ³n GonzΓ‘lez 7 Π»Π΅Ρ‚ Π½Π°Π·Π°Π΄ β€’ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ anonymous 7 Π»Π΅Ρ‚ Π½Π°Π·Π°Π΄ β€’ 1

Hi,

I took a look inside this chapter.

At the proposed example, you didn't remove the null checking:

$customer = ($order->customer !== <b>null</b>) ?
  $order->customer :
  <b>new</b> NullCustomer;

So, I don't see the worth of this solution...or I don't understand your suggestion.

Best regards,

Abelardo.

ΠžΡ‚Π²Π΅Ρ‚

ΠžΡ‚Π²Π΅Ρ‚
Answered

Hi Alberado!


I'm sorry for the very late reply.Β I think the non-obvious part of the examples is that this null check can be shifted to the place where you get the customer instance originally, a getter for example. Then you can eliminate dozens of null checks across the code that uses the customer object for a price of one initial null check in the getter.

ΠžΡ‚Π²Π΅Ρ‚
Answered

Hi Alberado!


I'm sorry for the very late reply.Β I think the non-obvious part of the examples is that this null check can be shifted to the place where you get the customer instance originally, a getter for example. Then you can eliminate dozens of null checks across the code that uses the customer object for a price of one initial null check in the getter.

БСрвис ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠ² Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π½Π° ΠΏΠ»Π°Ρ‚Ρ„ΠΎΡ€ΠΌΠ΅ UserEcho