Skip to content

Instantly share code, notes, and snippets.

View brzuchal's full-sized avatar

Michał Marcin Brzuchalski brzuchal

View GitHub Profile
@brzuchal
brzuchal / 01-index.php
Last active January 15, 2017 12:48
PHP Module
<?php
require 'module.php';
require 'doctrine-module.php';
$myClass = MyVendor\MyModulePackageBundle\Domain\MyClass();
echo $myClass::module; // MyVendor\MyModulePackageBundle
var_dump(file_exists('vendor+package:resources/config.yml')); // true
$driver = new Doctrine\DBAL\Driver\Mysql();
PHP RFC: Ommit double-slash in user Stream Wrapper URI

  * Version: 1.0
  * Date: 2017-01-23
  * Author: Michał Brzuchalski <michal.brzuchalski@gmail.com>
  * Status: Draft
  * First Published at: http://wiki.php.net/rfc/ommit-double-slash-in-user-stream-wrapper-uri

Introduction

Regarding RFC 2396 defining URI Generic Syntax which specifies URI Syntactic Components:

@brzuchal
brzuchal / Makefile
Created April 18, 2017 08:03
Embeding PHP7
CC=gcc
CFLAGS=-c $(shell php-config --includes ) -Wall -g
LDFLAGS=$(shell php-config --ldflags )
all: embed.c
$(CC) -o embed.o embed.c $(CFLAGS)
$(CC) -o embed embed.o $(LDFLAGS)
As this is a language change, a 2/3 majority is required.
The vote is a straight Yes/No vote for accepting the RFC and merging the patch.
The additional vote is also a straight Yes/No vote for accepting variance behaviour on object type.
<doodle title="Accept the object typehint RFC for PHP 7.2?" auth="brzuchal" voteType="single" closed="false">
* Yes
* No
</doodle>
<doodle title="Object type should implement variance?" auth="brzuchal" voteType="single" closed="false">
@brzuchal
brzuchal / short-closures.md
Last active July 27, 2017 12:36
Callable Dereference

Introduction

Callables syntactically have few ways of passing them around. This RFC is supposed to introduce unified short way of creating closures from callables and reduce callable type hint checks at runtime by using closures.

Callable syntax

Currently there are few ways of declaring callables and they differ while dereferencing function or method. Assuming given example we'll gonan discuss all available 6 ways passing callable.

@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()) {
@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 / 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 / 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 / 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)"