<?php
// Positional arguments.
$pieces = explode('-', 'piece1-piece2-piece3');
// Named arguments.
$pieces = explode(delimiter: '-', string: 'piece1-piece2-piece3');
// or
$pieces = explode(string: 'piece1-piece2-piece3', delimiter: '-');
<?php
$street_number = null;
$current_user = \Drupal::currentUser();
if ($current_user !== NULL) {
$account = $current_user->getAccount();
if ($account !== NULL) {
$address = $account->getAddress();
if ($address !== NULL) {
$street_number = $address->getStreetNumber();
}
}
}
Replace by
<?php
$street_number = \Drupal::currentUser()?->getAccount()?->getAddress()?->getStreetNumber();
<?php
str_contains("abc", "a"); // true
str_contains("abc", "d"); // false
// $needle is an empty string
str_contains("abc", ""); // true
str_contains("", ""); // true
<?php
str_starts_with('Said', 'Sa'); // returns TRUE
str_ends_with('EL FAZNI', 'SA'); // returns FALSE
PHP RFC: Add str_starts_with() and str_ends_with() functions
PHP7
<?php
class Point {
public float $x;
public float $y;
public float $z;
public function __construct(
float $x = 0.0,
float $y = 0.0,
float $z = 0.0,
) {
$this->x = $x;
$this->y = $y;
$this->z = $z;
}
}
PHP8
<?php
class Point {
public function __construct(
public float $x = 0.0,
public float $y = 0.0,
public float $z = 0.0,
) {}
}
PHP RFC: Constructor Property Promotion
Weak Maps https://wiki.php.net/rfc/weak_maps Attributes v2 https://wiki.php.net/rfc/attributes_v2
PHP8
<?php
function foo(string $a, string $b, ?string $c = null, ?string $d = null)
{ /* … */ }
foo(
b: 'value b',
a: 'value a',
d: 'value d',
);