This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Existing functionality | |
function wrapLogger(LoggerInterface $existingLogger, string $myExtraContextValue) { | |
// Values can only be passed in via the constructor | |
$delegatingLogger = new class($existingLogger, $myExtraContextValue) extends AbstractLogger { | |
public function __construct( | |
// Constructor property promotion simplifies this, but we still need to declare private properties | |
private LoggerInterface $delegateTo, | |
private string $extraContextValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
$sslLabsData = json_decode(file_get_contents('https://api.ssllabs.com/api/v3/getClients'), true); | |
$comparisonPolicies = []; | |
$comparisonPolicies['EC2 FS-1-2-Res-2020-10'] = [ | |
'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256', | |
'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384', | |
'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here are three things I'd like to see in any new auto-capturing closures RFC: | |
1. JUSTIFICATION | |
Don't assume that everyone already thinks it's necessary and desirable. | |
Try to come up with some real-life examples where you would want to use it. | |
Acknowledge the possible down-sides, and explain why you think they're | |
justified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Transaction implements ContextManager | |
{ | |
public function __construct(private Database $db) {} | |
public function contextEnter() { | |
$this->db->beginTransaction(); | |
// Could return some other representation of the transaction if appropriate | |
return $this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Apis { | |
static function JsonGET( string $api_url, array $args = array() ) { | |
try { | |
$wp_error = null; | |
$args = wp_parse_args( $args, array( | |
'response_type' => ARRAY_A, | |
) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$xml = <<<XML | |
<foo> | |
<bar baz="bob">1<bing>bang</bing></bar> | |
<bar>2</bar> | |
</foo> | |
XML; | |
$sx = simplexml_load_string($xml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--TEST-- | |
Ignore 100 Continue returned by HTTP/1.1 servers | |
--INI-- | |
allow_url_fopen=1 | |
--SKIPIF-- | |
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?> | |
--FILE-- | |
<?php | |
require 'server.inc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$options = [ | |
'http' => [ | |
'protocol_version' => '1.1', | |
'header' => 'Connection: Close' | |
], | |
]; | |
$ctx = stream_context_create($options); | |
echo file_get_contents('https://http2.golang.org/reqinfo', false, $ctx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create Table test ( testjson jsonb ); | |
Insert Into test ( testjson ) Values ( '[{"sid":"12345284239407942"}]'::jsonb ); | |
Select testjson->>'sid' From test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Closable_PDO | |
{ | |
private $pdo; | |
public function __construct($dsn, $username, $password, $options) { | |
$this->pdo = new PDO($dsn, $username, $password, $options); | |
} | |
NewerOlder