Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Post Made Community Wiki
added new example
Source Link
Michał Tatarynowicz

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. Another example:

$record = get_record($id) 
  or throw new Exception("...");

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored.

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. Another example:

$record = get_record($id) 
  or throw new Exception("...");
deleted 35 characters in body
Source Link
Michał Tatarynowicz

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. This can be also useful for validating user input:

preg_match(REGEXP_EMAIL, $_POST['email'])
  or $errors['email'] = "Please provide a valid e-mail address."

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. This can be also useful for validating user input:

preg_match(REGEXP_EMAIL, $_POST['email'])
  or $errors['email'] = "Please provide a valid e-mail address."

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored.

added 11 characters in body
Source Link
Michał Tatarynowicz

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. This can be also useful for validating user input:

valid::emailpreg_match($email)REGEXP_EMAIL, $_POST['email'])
  or $errors['email'] = "Please provide a valid e-mail address."

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. This can be also useful for validating user input:

valid::email($email) 
  or $errors['email'] = "Please provide a valid e-mail address."

You can take advantage of the fact that the or operator has lower precedence than = to do this:

$page = (int) @$_GET['page'] 
  or $page = 1;

If the value of the first assignment evaluates to true, the second assignment is ignored. This can be also useful for validating user input:

preg_match(REGEXP_EMAIL, $_POST['email'])
  or $errors['email'] = "Please provide a valid e-mail address."
added more examples
Source Link
Michał Tatarynowicz
Loading
fixed grammar
Source Link
Michał Tatarynowicz
Loading
Source Link
Michał Tatarynowicz
Loading
lang-php