Skip to content

Instantly share code, notes, and snippets.

@iluuu1994
iluuu1994 / y.output
Created April 11, 2020 16:20
PHP reduce/reduce conflict
This file has been truncated, but you can view the full file.
Terminals unused in grammar
"comment (T_COMMENT)"
"doc comment (T_DOC_COMMENT)"
"open tag (T_OPEN_TAG)"
"open tag with echo (T_OPEN_TAG_WITH_ECHO)"
"close tag (T_CLOSE_TAG)"
"whitespace (T_WHITESPACE)"
"invalid character (T_BAD_CHARACTER)"
T_ERROR
@iluuu1994
iluuu1994 / boundaries.php
Last active June 7, 2020 13:54
Boundaries enum example
<?php
enum Boundaries
{
case includeNone;
case includeStart;
case includeEnd;
case includeAll;
public function startIncluded(): bool
@iluuu1994
iluuu1994 / test.php
Created June 14, 2020 18:15
Partial POC
<?php
function sum(int $a, int $b, &$c) {
$c = $a + $b;
return $c;
}
function reflection_param_to_string(\ReflectionParameter $reflectionParam, bool $useList = false) {
$string = '';
@iluuu1994
iluuu1994 / README.md
Last active June 20, 2020 16:17
=~= operator

=~= operator

// bool vs int
false =~= '' // true
false =~= '0' // false
false =~= 'false' // false
true =~= '1' // true
true =~= 'true' // false
@iluuu1994
iluuu1994 / 039.phpt
Created July 11, 2020 15:09
Match misoptimization
$_main:
; (lines=72, args=0, vars=1, tmps=19)
; (before optimizer)
; /tmp/php-src/Zend/tests/match/039.phpt:1-62
; return [] RANGE[0..0]
0000 ECHO string("--TEST--
Test match with duplicate conditions
--FILE--
")
0001 ASSIGN CV0($value) int(1)
<?php
function takes_ref(&$ref) {}
$foo = null;
takes_ref($foo?->bar);
// Can either:
// 1. Throw no error, pass null
// 2. Throw a "Cannot parameter 1 by reference" error
This file has been truncated, but you can view the full file.
Terminals unused in grammar
"comment (T_COMMENT)"
"doc comment (T_DOC_COMMENT)"
"open tag (T_OPEN_TAG)"
"open tag with echo (T_OPEN_TAG_WITH_ECHO)"
"close tag (T_CLOSE_TAG)"
"whitespace (T_WHITESPACE)"
"invalid character (T_BAD_CHARACTER)"
T_ERROR
@iluuu1994
iluuu1994 / enums.php
Created September 6, 2020 18:38
Compiled enums
<?php
enum Option {
case None;
case Some(mixed $value) {
public function availableForSome() {
var_dump($this->value);
}
};
> An Enumeration may have one or more case definitions, with no maximum, although at least one is required.
Could an enum with no values potentially be useful? If not, should we still allow it for consistencies sake?
> __toString, Do we want this part or not? I only thought of it while writing this. I don't know if it's good or bad.
Could be useful. Why not.
> The Enum Type may also implement an interface, which all Cases must then fulfill, directly or indirectly.