What's new in PHP land? 2024.1
@brisphp1
https://brisphp.com
#BrisPHP
Giveaway: brisphp.com/pizza
@brisphp1
https://brisphp.com
#BrisPHP
PHP 8.3 released
- 1200 commits (280 from foundation)
- 114 contributors
- 23 RFC (18 passed, 13 from foundation)
@brisphp1
https://brisphp.com
#BrisPHP
PHP Version Stats: Versions in use
@brisphp1
https://brisphp.com
#BrisPHP
PHP Version Stats: Growth over time
@brisphp1
https://brisphp.com
#BrisPHP
PHP Version Stats: Min required version
@brisphp1
https://brisphp.com
#BrisPHP
PHP 8.3: My faves
- #[\Override] attribute
- Typed class constants
- Better DateTime exceptions
@brisphp1
https://brisphp.com
#BrisPHP
PHP Foundation
- Added 4 for developers
- Had 207 applicants
- Total of 10 developers (part time)
- 2023 had $418k contributions
- PHP contributions grown 79%
@brisphp1
https://brisphp.com
#BrisPHP
PHP 8.4: Multibyte ucfirst & lclast
<?php
function mb_ucfirst(string $str, ?string $encoding = null): string
{
return mb_convert_case(
mb_substr($str, 0, 1, $encoding),
MB_CASE_TITLE,
$encoding
)
. mb_substr($str, 1, null, $encoding)
;
}
function mb_lcfirst(string $str, ?string $encoding = null): string
{
return mb_strtolower(
mb_substr($str, 0, 1, $encoding),
$encoding
)
. mb_substr($str, 1, null, $encoding)
;
}
@brisphp1
https://brisphp.com
#BrisPHP
PHP 8.4: Multibyte trim
- mb_trim()
- mb_ltrim()
- mb_rtrim()
@brisphp1
https://brisphp.com
#BrisPHP
<?php
function get_contents() {
file_get_contents("http://example.com");
// Variable secretly created in the local scope
// Array of headers as strings
var_dump($http_response_header);
}
get_contents();
// Warning: Undefined varable $http_response_header
var_dump($http_response_header);
PHP 8.4: $http_response_header
@brisphp1
https://brisphp.com
#BrisPHP
<?php
array(9) {
[0]=>
string(15) "HTTP/1.1 200 OK"
[1]=>
string(35) "Date: Sat, 12 Apr 2008 17:30:38 GMT"
[2]=>
string(29) "Server: Apache/2.2.3 (CentOS)"
[3]=>
string(44) "Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT"
[4]=>
string(27) "ETag: "280100-1b6-80bfd280""
[5]=>
string(20) "Accept-Ranges: bytes"
[6]=>
string(19) "Content-Length: 438"
[7]=>
string(17) "Connection: close"
[8]=>
string(38) "Content-Type: text/html; charset=UTF-8"
}
PHP 8.4: $http_response_header
@brisphp1
https://brisphp.com
#BrisPHP
PHP 8.4: $http_response_header
- Originally attempted to deprecate in 8.1
- Introduce replacements
- http_get_last_response_header()
- http_clear_last_response_header()
- NOT deprecating the variable yet
@brisphp1
https://brisphp.com
#BrisPHP
# <=8.3
opcache.jit=tracing
opcache.jit_buffer_size=0
# >= 8.4
opcache.jit=disable
opcache.jit_buffer_size=64m
PHP 8.4: JIT default settings
@brisphp1
https://brisphp.com
#BrisPHP
<?php
function foo(T1 $a, T2 $b = null, T3 $c) {}
function bar(T1 $a, ?T2 $b = null, T3 $c) {}
function test(T1 $a, T2|null $b = null, T3 $c) {}
PHP 8.4: Deprecate implicit null
@brisphp1
https://brisphp.com
#BrisPHP
<?php
// Only support <=HTML4.01
\DOMDocument::loadHTML()
\DOMDocument::loadHTMLFile()
// Supports HTML5
\DOM\HTMLDocument::createEmpty()
\DOM\HTMLDocument::createFromFile()
\DOM\HTMLDocument::createFromString()
// Drop in replacement for \DOMDocument
\DOM\XMLDocument::createEmpty()
\DOM\XMLDocument::createFromFile()
\DOM\XMLDocument::createFromString()
PHP 8.4: DOM HTML5 parsing
@brisphp1
https://brisphp.com
#BrisPHP
<?php
// This is a PUT request
var_dump($_POST); // []
var_dump($_FILES); // []
[$_POST, $_FILES] = request_parse_body();
var_dump($_POST); // [...]
var_dump($_FILES); // [...]
PHP 8.4: multipart/form-data for non-POST
@brisphp1
https://brisphp.com
#BrisPHP
<?php
ceil($number) === round($number, 0, PHP_ROUND_CEILING); //true
floor($number) === round($number, 0, PHP_ROUND_FLOOR); //true
PHP 8.4: New rounding modes
- PHP_ROUND_CELIING
- PHP_ROUND_FLOOR
- PHP_ROUND_AWAY_FROM_ZERO
- PHP_ROUND_TOWARD_ZERO
Questions?
@brisphp1
https://brisphp.com
#BrisPHP
Observability Panel
- Justin Hennessy
- Ben Plunkett
- Damian Maclennan
What's new in PHP land - 2024.1
By Nathan Dench
What's new in PHP land - 2024.1
- 54