PHP 5.4からPHP 7系への変換スクリプト | Will feel Tips
seen from United States

seen from T1

seen from Maldives
seen from Hong Kong SAR China

seen from T1
seen from United States
seen from United States

seen from Malaysia
seen from France
seen from Türkiye
seen from Indonesia
seen from United States
seen from Italy
seen from United States
seen from China
seen from United States

seen from United States
seen from Maldives
seen from United States
seen from China
PHP 5.4からPHP 7系への変換スクリプト | Will feel Tips

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Cómo resolver el problema de preg_replace con el modificador /e en Prestashop con PHP 5.4 o superior.
Cómo resolver el problema de preg_replace con el modificador /e en Prestashop con PHP 5.4 o superior.
With an update to a new virtual box from one of Ubuntu's cloud images to Raring Ringtail, PHP 5.4 has become the default PHP version. With PHP 5.3's lifetime coming to an end, it is recommended to start looking at 5.4 among other reasons (huge performance boost chief amongst them).
I've also made the VM box a bit more flexible. Now the bound hostnames are configurable as well as the box hostname. Certain aspects of the machine itself are now configurable, such as system memory and mount type (NFS or not).
Overall, a much needed update to my personal development environment.
There's no rose without thorns
I did encounter a rather nasty Ruby bug with Opscode's PHP cookbook outlined here. That being said, the issue is easy to fix locally until the pull request is merged in and made available downstream.
Using PHP5.4 traits in Mongounit to allow a combination of databases to utilize fixtures within the same test case.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
O que todo programador deve saber sobre PHP 5.4
Traits
PHP é uma linguagem de herança simples. Isto é, uma subclasse só pode herdar de uma superclasse única, o que limita os métodos que podem ser usados em várias classes independentes. Assim, PHP 5,4 inclui suporte para traits - uma característica há muito tempo aguardada que melhora drasticamente a flexibilidade da linguagem e reduz o código repetitivo, inútil. Traits são essencialmente conjuntos de métodos que podem ser reutilizados em várias classes. A abordagem clássica implicaria a criação de duas instâncias do mesmo código, caso este código precise ser utilizado em mais de uma classe. Mas, com traits, você pode criar um único método e chamar sobre ela em duas classes diferentes, sem repetir o código, o que torna mais enxuta para código, mais elegante. Exemplos
Melhorias nos Arrays
PHP 5,4 inclui duas melhorias significativas para Arrays - suporte para a sintaxe de matriz curta e Dereferencing de arrays de chamadas de função e método. Estas alterações tornam o código mais fácil de ler e gerenciar. Sintaxe curta de Array tem sido definida em PHP de uma forma bem parecida à sintaxe do JSON. Assim, um Array pode ser definido assim:
$a = [1, 2, 3, 4]; $b = ['um' => 'dois', 'três' => 'quatro'];
Dereferencing Array, por outro lado, elimina a necessidade de definir variáveis temporárias e agiliza o código. Assim, enquanto nas versões anteriores do PHP, você tinha que armazenar o valor de uma função em uma variável, e depois usar a variável . No PHP 5.4, você pode invocar o valor armazenado diretamente. Por exemplo, anteriormente, você tinha que fazer isso:
food = explode(",", "pizzahut,burgerking,kfc,mcdonalds"); echo $food[3]; // mcdonalds
Agora você pode simplesmente fazer isso:
echo explode(",", "pizzahut,burgerking,kfc,mcdonalds")[3]; // mcdonalds
$this suportado em Closures
Funções anônimas ou sem nome são chamados 'closures'. Estas funções são muito úteis como o valor de parâmetros de chamada de retorno. Com suporte para $ this, você pode chamar em qualquer propriedade do objeto em qualquer função anônima, eliminando a necessidade de hacks. Exemplo e explicação de closures no manual PHP.net
Built-in Web Server
Como o foco do PHP 5.4 é para agilizar o processo de desenvolvimento, ele possui um servidor web embutido no modo CLI na porta 8000 para facilitar o rápido desenvolvimento e teste, eliminando assim a necessidade de configurar um servidor HTTPD Apache. Esse servidor pode ser chamado usando um comando simples:
$ cd ~/public_html $ php –S localhost:8000
Por favor entenda que este CLI web-servidor deve ser utilizado apenas para fins de teste e não pode ser utilizada para a produção real.
Agora < ?= é suportado por default
A configuração short_open_tag no php.ini permite a utilização de < ?=. Agora no PHP 5.4 esta opção vem habilitada por default. Então em vez de escrever:
você pode escrever:
= $teste; ">
Texto traduzido e adaptado do post What Every Developer Must Know About PHP 5.4
ISO-2022-JP-2004、EUC-JIS-2004、Shift JIS-2004 での第2面の漢字のバイト列
PHP 5.4 の mbstring は ISO-2022-JP-2004、EUC-JIS-2004、Shift JIS-2004 をサポートするようになった。これらのエンコーディングでは JIS X 0213:2004 で追加された第3、第4水準の漢字を扱うことができる。試しに山月記の登場人物である「袁傪」(U+8870、U+50AA)の「傪」をそれぞれのエンコーディングでのバイト表現で書き、それらを UTF-8 に変換してターミナルに表示させることができた。
var_dump( mb_convert_encoding("\x1B\x24\x28\x50"."\x21\x6F"."\x1B\x28\x42", 'UTF-8', 'ISO-2022-JP-2004'), mb_convert_encoding("\x8F\xA1\xEF", 'UTF-8', 'EUC-JP-2004'), mb_convert_encoding("\xF0\x8F", 'UTF-8', 'SJIS-2004'), );
対照実験として、従来の ISO-2022-JP、EUC-JP、SJIS から UTF-8 に変換したところ、無効な文字をあらわすはてな記号に置き換わった。
var_dump( mb_convert_encoding("\x1B\x24\x28\x50"."\x21\x6F"."\x1B\x28\x42", 'UTF-8', 'ISO-2022-JP'), mb_convert_encoding("\x8F\xA1\xEF", 'UTF-8', 'EUC-JP'), mb_convert_encoding("\xF0\x8F", 'UTF-8', 'SJIS') );
PCRE 関数で UTF-8 の文字列の長さを得る
mb_strlen を使えない環境で UTF-8 の文字数をカウントする
PCRE 関数で UTF-8 の文字列の長さを得る
不正なバイトを含む文字列の長さ
UTF-8 の長さを求める簡易な実装
preg_filter による文字列の長さのカウント
マルチバイト対応の文字列を配列に変換する関数 (PHP)
不正なバイト列を考慮して文字列の長さと変換配列を求める
preg_match を使って、不正なバイトを考慮した文字列の長さと変換配列を求める
2013年6月13日追記:より複雑なテストケースは「preg_match を使って、不正なバイトを考慮した文字列の長さと変換配列を求める」の記事を参照。
preg_split 関数で文字列を配列に分解して count 関数を使う方法もあるが、preg_match_all の戻り値がマッチした数であることを利用するほうが手っ取り早い。PHP 5.4 では第3引数のマッチした内容を投入する変数を省略できるようになった。
function utf8_strlen($str) { return count(preg_split('//us', $str, -1, PREG_SPLIT_NO_EMPTY)); } function utf8_strlen2($str) { return preg_match_all('/./us', $str); }
不正なバイト列を考慮すると次のようになる。
// http://stackoverflow.com/questions/8215050/replacing-invalid-utf-8-characters-by-question-marks-mbstring-substitute-charac/13695364#13695364 function utf8_strlen3($str) { // REPLACEMENT CHARACTER (U+FFFD) $substitute = "\xEF\xBF\xBD"; $ret = ''; $regex = '/ ([\x09\x0A\x0D\x20-\x7E] # U+0000 - U+007F |[\xC2-\xDF][\x80-\xBF] # U+0080 - U+07FF | \xE0[\xA0-\xBF][\x80-\xBF] # U+0800 - U+0FFF |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # U+1000 - U+CFFF | \xED[\x80-\x9F][\x80-\xBF] # U+D000 - U+D7FF | \xF0[\x90-\xBF][\x80-\xBF]{2} # U+10000 - U+3FFFF |[\xF1-\xF3][\x80-\xBF]{3} # U+40000 - U+FFFFF | \xF4[\x80-\x8F][\x80-\xBF]{2}) # U+100000 - U+10FFFF |(\xE0[\xA0-\xBF] # U+0800 - U+0FFF(incomplete) |[\xE1-\xEC\xEE\xEF][\x80-\xBF] # U+1000 - U+CFFF(incomplete) | \xED[\x80-\x9F] # U+D000 - U+D7FF(incomplete) | \xF0[\x90-\xBF][\x80-\xBF]? # U+10000 - U+3FFFF(incomplete) |[\xF1-\xF3][\x80-\xBF]{1,2} # U+40000 - U+FFFFF(incomplete) | \xF4[\x80-\x8F][\x80-\xBF]?) # U+100000 - U+10FFFF(incomplete) |(.) # invalid 1-byte /xs'; $offset = 0; // $offset: the place to start the search (in bytes) // $matches[1]: valid character // $matches[2]: invalid 3-byte or 4-byte character // $matches[3]: invalid 1-byte while (preg_match($regex, $str, $matches, 0, $offset)) { $offset += strlen($matches[0]); $ret += 1; } return $ret; }
2013年7月31日追記:preg_replace_callback を使う選択肢もある。
function utf8_strlen4($str) { $ret = 0; preg_replace_callback('/./su', function() use (&$ret) { $ret += 1; return ''; }, $str); return $ret; }
テストコードは次のとおり。
$str = 'あいうえおかきくけこさしすせそ'; var_dump( 15 === mb_strlen($str, 'UTF-8'), 15 === utf8_strlen($str), 15 === utf8_strlen2($str), 15 === utf8_strlen3($str), 15 === utf8_strlen4($str) );
ベンチマークをとると次のとおり。preg_match_all を使ったやりかたがもっとも速い結果となった。正規表現で不正なバイト列に対応しようとするとコストが大きく跳ね上がることがわかる。 不正なバイト列対策には htmlspecialchars と ENT_SUBSTITUTE オプションを使ったほうがよいだろう。
mb_strlen 0.18790292739868 preg_split 0.86319518089294 preg_match_all 0.32712507247925 不正なバイト列を考慮して preg_match 5.0946190357208 preg_replace_callback 1.3163239955902
function timer(array $callables, $repeat = 100000) { $ret = []; $save = $repeat; foreach ($callables as $key => $callable) { $start = microtime(true); do { $callable(); } while($repeat -= 1); $stop = microtime(true); $ret[$key] = $stop - $start; $repeat = $save; } return $ret; } $str = 'あいうえおかきくけこさしすせそ'; foreach (timer([ 'mb_strlen' => function() use ($str) { mb_strlen($str, 'UTF-8'); }, 'preg_split' => function() use ($str) { utf8_strlen($str); }, 'preg_match_all' => function() use ($str) { utf8_strlen2($str); }, '不正なバイト列を考慮して preg_match' => function() use ($str) { utf8_strlen3($str); }, 'preg_replace_callback' => function() use ($str) { utf8_strlen4($str); } ]) as $key => $value) { echo $key, PHP_EOL, $value, PHP_EOL; }