Skip to content

Instantly share code, notes, and snippets.

@do-aki
do-aki / ParameterTypeWidening.php
Created February 13, 2018 10:47
Parameter Type Widening に関して
<?php
class ParentClassA { function f(stdClass $a) {} }
class ChildClassA extends ParentClassA { function f($a) {} }
/*
7.2 の Parameter Type Widening (https://wiki.php.net/rfc/parameter-no-type-variance) によって、
上記 ParentClassA/ChildClassA は ok になった。
(new ParentClassA())->f(new stdClass()) に対して
@do-aki
do-aki / EnumTrait_Sample.php
Last active February 28, 2018 15:03
EnumTrait usage
<?php
final class GameDifficulty
{
const HARD = 'hard';
const NORMAL = 'normal';
const EASY = 'easy';
use EnumTrait {
constant as public HARD;
constant as public NORMAL;
<?php
trait EnumTrait
{
/** @var static[] */
private static $instance;
/** @var mixed value of constant */
private $value;
/**
# スレッドA,B 生成前に実行
> create table t1( id int not null auto_increment, hoge varchar(255) not null, primary key(id) )engine=innodb;
> insert into t1 values (1, "hoge");
スレッドA
> drop table t1;
> create table t1( id int not null auto_increment, primary key(id) )engine=innodb;
> insert into t1 values (1);
<?php
require 'vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
$html = <<<'HTML'
<!doctype html>
<form>
<input type="image" name="date[2016-03-16]" />
</form>
--- zend_inline_hash_func-5.6.16» 2015-12-10 22:02:42.179337112 +0900
+++ zend_inline_hash_func-7.0.0»2015-12-10 22:03:03.595338278 +0900
@@ -14,7 +14,7 @@
* numbers are not useable at all. The remaining 128 odd numbers
* (except for the number 1) work more or less all equally well. They
* all distribute in an acceptable way and this way fill a hash table
- * with an average percent of approx. 86%._
+ * with an average percent of approx. 86%.
*
* If one compares the Chi^2 values of the variants, the number 33 not
--- php-5.6.16/ext/skeleton/skeleton.c 2015-11-26 05:28:38.000000000 +0900
+++ php-7.0.0/ext/skeleton/skeleton.c 2015-12-01 22:36:41.000000000 +0900
@@ -36,20 +36,21 @@
PHP_FUNCTION(confirm_extname_compiled)
{
char *arg = NULL;
- int arg_len, len;
- char *strg;
+ size_t arg_len, len;
+ zend_string *strg;
<?php
namespace sample;
use dooaki\Phroonga\Groonga;
use dooaki\Phroonga\GroongaEntity;
class Message {
use GroongaEntity;
public static function _schema() {
<?php
$ctx = grn_get_default_ctx(); // grn_ctx_open(0)
$db = grn_db_open_or_create($ctx, '/tmp/db');
$table = grn_table_open_or_create(
$ctx,
'Site',
null, // path
GRN_TABLE_HASH_KEY,
<?php
$grn = grn_ctx_init();
grn_ctx_connect($grn, "localhost", 10043);
grn_ctx_send($grn, "table_create Site TABLE_HASH_KEY ShortText");
grn_ctx_recv($grn);
grn_ctx_send($grn, "column_create Site title COLUMN_SCALAR ShortText");
grn_ctx_recv($grn);