@brisphp1
https://brisphp.com
#BrisPHP
@brisphp1
https://brisphp.com
#BrisPHP
@brisphp1
https://brisphp.com
#BrisPHP
@brisphp1
https://brisphp.com
#BrisPHP
@brisphp1
https://brisphp.com
#BrisPHP
function passwordHash(string $password) {
var_dump(debug_backtrace());
}
passwordHash('hunter2');
array(1) {
[0]=>
array(4) {
["file"]=> string(38) "..."
["line"]=> int(9)
["function"]=> string(3) "passwordHash"
["args"]=> array(1) {
[0]=> string(38) "hunter2"
}
}
}
@brisphp1
https://brisphp.com
#BrisPHP
function passwordHash(#[SensitiveParameter] string $password) {
var_dump(debug_backtrace());
}
passwordHash('hunter2');
array(1) {
[0]=>
array(4) {
["file"]=> string(38) "..."
["line"]=> int(9)
["function"]=> string(3) "passwordHash"
["args"]=> array(1) {
[0]=> object(SensitiveParameterValue)#1 (0) {
}
}
}
}
@brisphp1
https://brisphp.com
#BrisPHP
preg_match returns:
Note: Named capture groups are actually returned twice.
@brisphp1
https://brisphp.com
#BrisPHP
preg_match('/(\w)-(?P<num>\d+)-(\w)/', 'a-123-b', $matches);
array(5) {
[0]=> string(7) "a-123-b"
[1]=> string(1) "a"
["num"]=> string(3) "123"
[2]=> string(3) "123"
[3]=> string(1) "b"
}
@brisphp1
https://brisphp.com
#BrisPHP
preg_match with `/n` modifier returns:
Note: Named capture groups are still returned twice.
@brisphp1
https://brisphp.com
#BrisPHP
preg_match('/(\w)-(?P<num>\d+)-(\w)/n', 'a-123-b', $matches);
array(3) {
[0]=> string(7) "a-123-b"
["num"]=> string(3) "123"
[1]=> string(3) "123"
}
preg_match('/(?:\w)-(?P<num>\d+)-(?:\w)/', 'a-123-b', $matches);
Equivalent to non-named groups being non-capturing groups
@brisphp1
https://brisphp.com
#BrisPHP
$string = str_repeat('a', 1024 * 1024 * 4);
memory_get_peak_usage(); // 4590752
unset($string);
$string = str_repeat('a', 1024 * 1024 * 3);
memory_get_peak_usage(); // 4590752
Peak memory usage is the max memory used in the entire run
@brisphp1
https://brisphp.com
#BrisPHP
$string = str_repeat('a', 1024 * 1024 * 4);
memory_get_peak_usage(); // 4590752
unset($string);
memory_reset_peak_usage();
$string = str_repeat('a', 1024 * 1024 * 3);
memory_get_peak_usage(); // 3542648
Reset to record different peaks across different invocations
@brisphp1
https://brisphp.com
#BrisPHP
class MyValueObject {
public readonly string $myValue;
}
readonly class MyValueObject {
public string $myValue;
}
@brisphp1
https://brisphp.com
#BrisPHP
class Foo {
private true $processed;
public function process(string|int|true $value): true {
}
}
function foo(true|bool $value) {}
// Fatal error: Duplicate type true is redundant
function foo(true|false $value) {}
// Fatal error: Duplicate type true is redundant
function foo(true&string $value) {}
// Fatal error: Type true cannot be part of an intersection type
@brisphp1
https://brisphp.com
#BrisPHP
Deprecated because:
// Exactly what utf8_encode does
mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1');
// Try to guess the correct character encoding first
mb_convert_encoding($string, 'UTF-8', mb_list_encodings());
@brisphp1
https://brisphp.com
#BrisPHP