Knowledgebase

Variables, Types and Arrays Print

  • phplaravel, php, guide, howto, solution, zillionkinghost, hosting, support
  • 0

The basics.

WHAT A VARIABLE IS

A name holding a value, marked with a leading symbol.

WHAT TYPES EXIST

Text Whole numbers Decimal numbers True and false Arrays Objects The absence of a value

WHAT ARRAYS DO

Hold several values, either in order or keyed by name.

WHY THEY MATTER SO MUCH IN PHP

Almost everything arrives as an array: form data, query results, configuration.

WHAT TO KNOW ABOUT TYPE HANDLING

PHP will convert between types in many situations.

WHY THAT IS DANGEROUS

Comparisons can succeed where you did not intend.

WHAT TO DO ABOUT IT

Use strict comparison, which checks type as well as value.

Always, unless you have a reason not to.

WHAT ELSE TO ADOPT

Declaring strict types at the top of each file, so conversions are rejected rather than performed silently.

WHY

It turns a class of silent bugs into visible errors.

WHAT TO AVOID

Relying on automatic conversion Loose comparisons on values from outside


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot