Questions tagged [nullsafe]

6 questions
28
votes
4 answers

Is there a "nullsafe operator" in PHP?

Is there any way to write the following statement using some kind of safe navigation operator? echo $data->getMyObject() != null ? $data->getMyObject()->getName() : ''; So that it looks like this: echo $data->getMyObject()?->getName();
Dennis
  • 1,027
  • 1
  • 14
  • 30
8
votes
2 answers

Why am I getting Undefined property: stdClass:: with php 8 nullsafe operator

Php 8.0 introduced the nullsafe operator which can be used like so $foo?->bar?->baz;. I have a code sample running on php 8.1 that throws the error Undefined property: stdClass::$first_name even though it is using the nullsafe operator: $reference =…
naghal
  • 537
  • 3
  • 19
4
votes
3 answers

How to use equals() and contains() to check nullable type of data? I suppose they are both string's methods, but why they behave differently?

CASE 1: it can compile and run. why no exception when null call equals() ? var myStr:String? = null if (myStr.equals("hello")) println("equals hello") else println("not equals hello") CASE 2: it cannot compile. I suppose it is similar to…
BBdo
  • 53
  • 3
2
votes
2 answers

Why does being null safe matter

I'm currently in the process of switching over from java to kotlin and one of the stated advantages that keeps popping up is that kotlin is Null safe and by default cant have variables or objects be assigned a null value but there are ways to assign…
1
vote
2 answers

How to handle generated code with Flutter null safety?

I'm using flutter retrofit package (https://pub.dev/packages/retrofit) but they doesn't have null safety version yet. When I run build and the generated code doesn't have the null check. How can't i solve this without manual add "// @dart=2.9" to…
Kyo Huu
  • 520
  • 7
  • 13
0
votes
1 answer

Kotlin Unparseable and - NullPointerException error

What I expect: the 'for loop' brings the number of columns that will be displayed in the table, the start date, and the end date are taken by an object. the transaction date is taken by a different object. The start date variable gets the exception…