Skip to content

Instantly share code, notes, and snippets.

Avatar

Kerem Güneş k-gun

View GitHub Profile
@k-gun
k-gun / ctype_print_unicode.php
Last active Dec 3, 2020
PHP "ctype_print" for unicode (UTF-8)...
View ctype_print_unicode.php
<?php
define("CTYPE_PRINT_UNICODE_PATTERN", "~^[\pL\pN\s\"\~". preg_quote("!#$%&'()*+,-./:;<=>?@[\]^_`{|}´") ."]+$~u");
function ctype_print_unicode($input) {
return preg_match(CTYPE_PRINT_UNICODE_PATTERN, $input);
}
print ctype_print_unicode("3 muços?"); // 1
@k-gun
k-gun / Element.prototype.classList.js
Last active Oct 28, 2020
Polyfill: Element.prototype.classList for IE8/9, Safari.
View Element.prototype.classList.js
/**
* Element.prototype.classList for IE8/9, Safari.
* @author Kerem Güneş <k-gun@mail.com>
* @copyright Released under the MIT License <https://opensource.org/licenses/MIT>
* @version 1.2
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
*/
;(function() {
// Helpers.
var trim = function(s) {
View promises.js
<script>
// Bu kodları bit html dosyası içine kaydedip aşağıda çalıştırmak
// istediğin /* ... */ alanları açabilirsin.
// Her "async function" bir "Promise" döndürür.
async function foo() {}
/* console.log(foo()) */
/* console.log(foo().then(x => console.log(x))) */
@k-gun
k-gun / Default (Linux).sublime-keymap
Last active Mar 11, 2020
Default (Linux).sublime-keymap
View 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" },
@k-gun
k-gun / Uninitialized typed properties 4.bug
Created Dec 8, 2019
Another "uninitialized" thing..
View Uninitialized typed properties 4.bug
class A { protected int $x; }
class AA extends A { protected $x; }
// -> PHP Fatal error: Type of acme\AA::$ must be int (as in class acme\A)
No var name here "acme\AA::$".
@k-gun
k-gun / Uninitialized typed properties 3.bug
Last active Dec 4, 2019
Another "uninitialized" thing..
View Uninitialized typed properties 3.bug
$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?)
@k-gun
k-gun / Uninitialized typed properties 2.bug
Created Nov 22, 2019
Weird behavior with uninitialized typed properties and __set/__get
View Uninitialized typed properties 2.bug
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) } } }.
@k-gun
k-gun / Uninitialized typed properties.bug
Last active Nov 22, 2019
php bugreport that was gone spam
View Uninitialized typed properties.bug
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;
View uninitialized stuff
// Java
class Foo { Integer i; }
class Test {
public static void main(String args[]) {
System.out.println(new Foo().i == null);
}
}
// JavaScript
View nö.php
<?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);
}
You can’t perform that action at this time.