Skip to content

Instantly share code, notes, and snippets.

View brzuchal's full-sized avatar

Michał Marcin Brzuchalski brzuchal

View GitHub Profile
@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.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 / 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 / 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 / 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 / package.ini
Last active August 14, 2019 06:01
PHP Package - Possible package definition declarations
[package]
name = MyVendor\MyLibrary
strict_types = 1
encoding = UTF-8
@brzuchal
brzuchal / data.php
Last active August 26, 2019 13:51
Data type PHP
<?php
data Foo {
var string $foo; // if not set then uninitialized
var bool $bar = false;
}
$foo = new Foo
{
foo: "baz",
@brzuchal
brzuchal / php.rfc
Last active March 19, 2021 20:03
PHP Structs Example
====== PHP RFC: Structs ======
* Version: 0.9
* Date: 2020-03-25
* Author: Michał Brzuchalski <[email protected]>
* Status: Draft
* First Published at: http://wiki.php.net/rfc/structs
Structures as a complex type solution for programmers in functional programming appears in few programming languages but differs in a solution taken there. Some languages like **C#** have both **classes** and **scructs** living aside in harmony.
@brzuchal
brzuchal / reflection.php
Created March 25, 2020 20:01
PHP Reflection in PHP Namespace
<?php
namespace {
class ReflectionClass extends \Php\ReflectionClass {}
class ReflectionType extends \Php\ReflectionTypeConstraint {}
class ReflectionNamedType extends \Php\ReflectionClassTypeConstraint {}
}
namespace Php {
abstract class ReflectionType implements Reflector {}
class ReflectionClass extends ReflectionType {}
class ReflectionTypeConstraint {}
@brzuchal
brzuchal / delegates.md
Last active March 31, 2020 13:57
PHP delegates

PHP RFC: Delegates

Declaration

To distinguish between classes and delegates a delegate keyword is used to precede delegate name. For FQN optimisations an additional use delegate clause should be placed in all imports and aliases block.

namespace MyApp;