Skip to content

Instantly share code, notes, and snippets.

@krmgns
krmgns / Uninitialized typed properties 3.bug
Last active December 4, 2019 17:44
Another "uninitialized" thing..
$foo = new class() {
var ?array $a;
function dump() { var_dump($this->a); }
function sort() { ksort($this->a); }
};
// E1: Error: Typed property class@anonymous::$a must not be accessed before initialization
$foo->dump();
// E2: TypeError: ksort() expects parameter 1 to be array, null given (should throw E1 cos its an uninitialized property?)
@krmgns
krmgns / Uninitialized typed properties 2.bug
Created November 22, 2019 21:08
Weird behavior with uninitialized typed properties and __set/__get
Link: https://bugs.php.net/bug.php?id=78859
---
Weird behavior with uninitialized typed properties and __set/__get
Seems calling a constructor is triggering __set magic for uninitialized typed properties. So it does not matter the property is public or private/protected.
I suppose the problem is __set/__get called before __construct when a type is given to a property. Also I if remove __get then I get object(acme\Options)#1 (1) { ["stack"]=> array(1) { ["stack"]=> array(1) { ["one"]=> int(1) } } }.
@krmgns
krmgns / Uninitialized typed properties.bug
Last active November 22, 2019 21:07
php bugreport that was gone spam
Link: https://bugs.php.net/bug.php?id=78809
---
Uninitialized typed properties
While throwing when try to access to any uninitialized typed property (eg: $o->x == null),
the codes below are just causing notice.
BTW, error message is so weird. We were expecting something like this;
@krmgns
krmgns / uninitialized stuff
Created November 13, 2019 18:27
uninitialized
// Java
class Foo { Integer i; }
class Test {
public static void main(String args[]) {
System.out.println(new Foo().i == null);
}
}
// JavaScript
@krmgns
krmgns / nö.php
Created November 12, 2019 16:25
nö!
<?php
// ok, cos converted to ?int = null, right?
function foo(int $i = null) {}
// ok, all ok, right?
$a = new class {
public $i;
public function check(): bool {
return ($this->i != null);
}
@krmgns
krmgns / salt-guid.js
Last active February 8, 2021 23:30
Generate randomized Salts & GUIDs.
const crypto = require('crypto');
const util = require('util');
const Salt = {
/**
* Length.
* @const int
*/
LENGTH: 128,
def fn_vector(words):
import re, locale
#global words
def slug(words):
return fn_slug(words)
i = 0
dic = {}
words = slug(words)
def fn_slug(words):
import re
#global words
chrs = {'ı':'i', 'ö':'o', 'ü':'u', 'ç':'c', 'ğ':'g', 'ş':'s',
'İ':'I', 'Ö':'O', 'Ü':'U', 'Ç':'C', 'Ğ':'G', 'Ş':'S'}
def lower(word):
return word.replace('İ', 'i').replace('I', 'ı').lower()
@krmgns
krmgns / Preferences.sublime-settings
Last active November 2, 2019 22:11
Preferences.sublime-settings
{
"added_words":
[
"uber",
"versioning"
],
"always_show_minimap_viewport": true,
"color_scheme": "Packages/Inspired GitHub Color Scheme/InspiredGitHub_2.tmTheme",
"default_line_ending": "unix",
"detect_indentation": false,
@krmgns
krmgns / Default (Linux).sublime-keymap
Last active March 11, 2020 21:34
Default (Linux).sublime-keymap
[
{ "keys": ["ctrl+q"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+q"], "command": "toggle_comment", "args": { "block": true } },
{ "keys": ["ctrl+shift+e"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["ctrl+shift+o"], "command": "prompt_open_folder" },
{ "keys": ["ctrl+shift+h"], "command": "goto_documentation" },
// { "keys": ["ctrl+1"], "command": "fold_all" },