Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 769 Bytes

File metadata and controls

22 lines (15 loc) · 769 Bytes

Literal String Polyfill

This is a draft of the LiteralString type to provide backwards compatability to older versions of PHP.

Usage

Create a LiteralString:

$string = LiteralString::from('SELECT * FROM users WHERE name = %s');

function query(LiteralString $query, array $variables) { /* code */ }

Literal strings retain much of their stringiness, even in strict mode:

assert(LiteralString::from("a value") === LiteralString::from("a value")); // note the triple equals
assert(LiteralString::from("a value") !== LiteralString::from("a different value"));
assert(LiteralString::from("A") < LiteralString::from("B"));
assert(LiteralString::from("A") . LiteralString::from("B") === "AB"); // note that it is no longer a literal string