Skip to content

Instantly share code, notes, and snippets.

View brzuchal's full-sized avatar

Michał Marcin Brzuchalski brzuchal

View GitHub Profile
@brzuchal
brzuchal / sealed-classes.md
Created March 19, 2019 11:56
Sealed classes RFC

Sealed classes

Introduction

A sealed type is one for which subclassing is restricted according to subclass names specified with the class’s declaration or to restrict to the same subclass namespace.

Sealed type is more like extended form of finality, where it is possible to list all class names allowed to extending from sealed class or permit only same namespace class to extend sealed class.

@brzuchal
brzuchal / non-typed-properties.out
Last active February 7, 2019 17:52
Testing __set against Typed Properties PHP7
string(10) "created_at"
string(10) "2019-02-05"
object(Message)#1 (5) {
["id"]=>
int(999)
["title"]=>
string(12) "Hello World!"
["message"]=>
string(23) "Here is your message..."
["time"]=>
@brzuchal
brzuchal / Dockerfile
Last active December 12, 2018 10:59
micro php container
FROM alpine:latest as builder
ENV PHP_INI_DIR /etc/php7
ENV PHP_VERSION 7.3.0
ENV PHP_FILENAME php-7.3.0.tar.xz
ENV PHP_SHA256 7d195cad55af8b288c3919c67023a14ff870a73e3acc2165a6d17a4850a560b5
RUN build_pkgs="build-base linux-headers pcre-dev gnupg autoconf file g++ gcc libc-dev make pkgconf re2c gnupg" \
&& runtime_pkgs="ca-certificates openssl zlib curl" \
&& apk add --update --no-cache --virtual .build-deps ${build_pkgs} \
@brzuchal
brzuchal / annotations.rfc.md
Last active September 14, 2018 13:59
Annotations

Introduction

Annotation is a form of syntactic metadata that can be added to source code. Annotations can be embeded in and read using reflection mechanism. Annotations known from Java or so called Attributes in C# and can be retained by VM at run-time and read via reflection. Annotations can be placed in classes, methods, properties and functions.

PHP offers only a single form of such metadata - doc-comments. In userland there exists some annotation reader libraries like Doctrine Annotations which is widely used for eg. to express object-relational mapping metadata.

@brzuchal
brzuchal / config.php
Last active April 18, 2018 08:45
PHP Packages
<?php
require 'autoload.php';
$someObject = new Vendor\Package\SomeClass(); // autoloader tries to load... what exactly??? need to load vendor package.php somehow
@brzuchal
brzuchal / annotations.diff
Last active February 1, 2018 12:07
PHP Annotations Syntax
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 2941546..b0ca01b 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -221,12 +221,14 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%token T_COALESCE "?? (T_COALESCE)"
%token T_POW "** (T_POW)"
%token T_POW_EQUAL "**= (T_POW_EQUAL)"
+%token T_AT "@ (T_AT)"
@brzuchal
brzuchal / src_Acme_Animal_Cat.php
Last active December 13, 2017 07:46
Packages in PHP
<?php
namespace Acme:Animal;
class Cat {
public function __construct() {
echo 'Created ' . self::class . ' from package ' . __PACKAGE__;
}
}
@brzuchal
brzuchal / TestFrameworkInATweet.php
Created November 9, 2017 09:38 — forked from mathiasverraes/TestFrameworkInATweet.php
A unit testing framework in a tweet.
<?php function it($m,$p){echo"\e[3".($p?"2m✔︎":"1m✘")."\e[0m It $m\n";if(!$p){$GLOBALS['e']=1;$d=debug_backtrace()[0];echo"ERROR {$d['file']}@{$d['line']}\n";}}register_shutdown_function(function(){echo"\e[1;3".(($e=@$GLOBALS['e'])?"7;41mFAIL":"2mOK")."\e[0m\n";die($e);});
@brzuchal
brzuchal / closure-expr.diff
Created June 7, 2017 11:36
Closure Syntax
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 92524c6..8ac8f55 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -240,7 +240,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> internal_functions_in_yacc
%type <ast> exit_expr scalar backticks_expr lexical_var function_call member_name property_name
%type <ast> variable_class_name dereferencable_scalar constant dereferencable
-%type <ast> callable_expr callable_variable static_member new_variable
+%type <ast> callable_expr callable_variable static_member new_variable closure_expr
@brzuchal
brzuchal / document.php
Created May 30, 2017 18:22 — forked from krakjoe/document.php
for generating stubs for a loaded extension
<?php
/*
usage: php document.php --ext name [--output document.txt]
*/
function prototype(Reflector $reflector) {
$elements = [];
switch (get_class($reflector)) {
case "ReflectionClass":
if ($reflector->isFinal()) {