SlideShare a Scribd company logo
PHP5.4

@tanakahisateru
ABOUT ME

•              (               )

• @tanakahisateru

• https://github.com/tanakahisateru

• Firebug, FireCookie, jEdit

• ...and   Pinoco
関西PHP勉強会 php5.4つまみぐい
•   PHP5.4

•   Array Short Syntax

•   Built-in Server

•   Trait

•   Closure

•
:
PHP5.4


Graham     ( @predominant )
                                  :)
     http://tipshare.info/view/
   4ec326d04b2122ce49000000
PHP5.4
PHP 5.4 RC1 (2011/11/11)

• http://www.php.net/archive/2011.php#id2011-11-11-1
PHP
          PHP 5.4
    http://www.1x1.jp/blog/
            2011/06/
try_new_php_without_update
     _current_version.html

            configure      make
•   Windows

    •   http://windows.php.net/qa/



•   Mac

    •   XCode + MacPorts or Homebrew

•   Linux

    •
% curl -o php-5.4.0RC1.tar.gz http://downloads.php.net/stas/
php-5.4.0RC1.tar.gz
% tar xzf php-5.4.0RC1.tar.gz
% cd php-5.4.0RC1
% ./configure 
--prefix=/opt/local/php/5.4 
--bindir=/opt/local/bin 
--with-config-file-path=/opt/local/php/5.4/etc 
--with-config-file-scan-dir=/opt/local/php/5.4/var/db 
--mandir=/opt/local/php/5.4/share/man 
--infodir=/opt/local/php/5.4/share/info 
--program-suffix=-5.4 
--with-apxs2=/opt/local/apache2/bin/apxs 
(      https://gist.github.com/1344162           )
% make
(make install)
sapi/cli/php


      configure


         PHP
% sapi/cli/php -v
PHP 5.4.0RC1 (cli) (built: Nov 23 2011 23:08:40)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2011 Zend
Technologies




% sapi/cli/php -a
Interactive shell

php >
php > echo “Hello Worldn”;
Hello World

php > print_r(array_map(function($x){ return $x * 2; },
range(0,9)));
Array
(
    [0] => 0
    [1] => 2
    [2] => 4
    [3] => 6
    [4] => 8
    [5] => 10
    [6] => 12
    [7] => 14
    [8] => 16
    [9] => 18
)                                   :
php > echo 0xff == 0b11111111, "n";
1
ARRAY SHORT SYNTAX
array(1, 2, 3)


[1, 2, 3]
array(‘a’=>1, ‘b’=>2)


[‘a’=>1, ‘b’=>2]
@rsky




https://wiki.php.net/rfc/
 shortsyntaxforarrays
var $belongsTo = array(
! 'User'
);
var $hasMany = array(
    'Photo' => array(
        'order' => 'number'
    )
);

var $belongsTo = [
! 'User'
];
var $hasMany = [
    'Photo' => [
        'order' => 'number'
    ]
];
$this->render('list', array(
  'posts' => Post::find(array(
     'limit' => Config::get('postsPerPage',
       array('context'=>'blog', 'default'=>10)),
  ))
));

                                              ?
$this->render('list', [
  'posts' => Post::find([
     'limit' => Config::get('postsPerPage',
       ['context'=>'blog', 'default'=>10]),
  ])
]);
関西PHP勉強会 php5.4つまみぐい
$this->render('list', array(
  'posts' => Post::find(array(
     'limit' => Config::get('postsPerPage',
       array('context'=>'blog', 'default'=>10)),
  ))
));




$this->render('list', [
  'posts' => Post::find([
     'limit' => Config::get('postsPerPage',
       ['context'=>'blog', 'default'=>10]),
  ])
]);
$this->render('list', array(
  'posts' => Post::find(array(
     'limit' => Config::get('postsPerPage',
       array('context'=>'blog', 'default'=>10)),
  ))
));




$this->render('list', [
  'posts' => Post::find([
     'limit' => Config::get('postsPerPage',
       ['context'=>'blog', 'default'=>10]),
  ])
]);


                               Array
$this->render('list', array(
  'posts' => Post::find(array(
     'limit' => Config::get('postsPerPage',
       array('context'=>'blog', 'default'=>10)),
  ))
));




$this->render('list', [
  'posts' => Post::find([
     'limit' => Config::get('postsPerPage',
       ['context'=>'blog', 'default'=>10]),
  ])
]);




          [ ... ]
ARRAY SHORT SYNTAX

•                  →

•


• PHP


•          Array
ARRAY SHORT SYNTAX


•   PHP   array       YAML



•   PHP
BUILT-IN SERVER
PHP
Web
% sapi/cli/php -S localhost:8080
•   Javascript Flash     file://       API
        →                    PHP5.4

•           Apache



•                      PHP
.htaccess   mod_rewrite
PHP
% sapi/cli/php -S localhost:8080 builtin-server.php
list($path, $param) = array_merge(
     preg_split('/?/', $_SERVER['REQUEST_URI'], 2), ['', '']
);
if($path != '/' && (file_exists('app/webroot' . $path)))
{
     header(sprintf('Location: http://%s/app/webroot%s',
         $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])); exit;
}
else if($path != '/' && (file_exists('./' . $path)))
{
     return false;
}
else
{
     $_SERVER['PATH_INFO'] = $path;
     require 'app/webroot/index.php';
}
% ~/php54/php-5.4.0RC1/sapi/cli/php -S localhost:8080
builtin-server.php
関西PHP勉強会 php5.4つまみぐい
PHP 5.4.0RC1 Development Server started at Thu Nov 24 02:11:37 2011
Listening on localhost:8080
Document root is /Users/tanakahisateru/Sites/cakephp2
Press Ctrl-C to quit.
[Thu Nov 24 02:11:42 2011] ::1:63556 [200]: /app/webroot/css/cake.generic.css
[Thu Nov 24 02:11:42 2011] ::1:63557 [200]: /app/webroot/img/cake.power.gif
[Thu Nov 24 02:11:42 2011] ::1:63558 [200]: /app/webroot/img/cake.icon.png
[Thu Nov 24 02:11:42 2011] ::1:63564 [200]: /app/webroot/favicon.ico
MacPorts       MySQL
                      php.ini
 % ~/php54/php-5.4.0RC1/ sapi/cli/php -c ~/php54/
 php-5.4.0RC1/ -S localhost:8080 builtin-server.php



              ~/php54/php-5.4.0RC1/php.ini
[Pdo_mysql]
pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock



          MySQL
BUILT-IN SERVER

•                                           URL
                              OK

• Apache


•                 PHP5.3
                                   Apache
    mod_php          PHP5.4
TRAIT
NO.1
TRAIT

•


•   Ruby         mixin

•          PHP               (instanceof   )



•
関西PHP勉強会 php5.4つまみぐい
1
         INCLUDE / REQUIRE

•


• HTML


•                          /
2

•




•




•   class AppModel extends Model
    class GuestUser extends AppModel
    class AdminUser extends AppModel
                                User
class AppModel extends Model {
}

class GuestUser extends AppModel {
    public function getDisplayLabel() {
        ...;
    }
}                                           !!
class AdminUser extends AppModel {
    public function getDisplayLabel() {
        ...;
    }
    public function getAdminRioleType() {
        ...;
    }
}
class AppModel extends Model {
    public function getDisplayLabel() {
        ...;
    }
}

class GuestUser extends AppModel {
}

class AdminUser extends AppModel {
    public function getAdminRioleType() {
        ...;
    }
}
class AppModel extends Model {
    public function getDisplayLabel() {
        return $this->username . “   ”;
    }
}

class GuestUser extends AppModel {
}

class AdminUser extends AppModel {
    public function getAdminRoleType() {
        ...;
    }
}

class Comment extends AppModel {
    // username                      ←
}
UserModel.inc
    public function getDisplayLabel() {
        return $this->username . “   ”;
    }

class GuestUser extends AppModel {
    require ‘UserModel.inc’;
}

class AdminUser extends AppModel {
    require ‘UserModel.inc’;
    public function getAdminRoleType() {
        ...;
    }
}

class Comment extends AppModel {
}                                                ...
        require             =              orz
trait UserModel {
    public function getDisplayLabel() {
        return $this->username . “   ”;
    }
}

class GuestUser extends AppModel {
    use UserModel;
}

class AdminUser extends AppModel {
    use UserModel;
    public function getAdminRoleType() {
        ...;
    }
}

class Comment extends AppModel {
}
関西PHP勉強会 php5.4つまみぐい
trait PersistentModel {
    public function save() {
    }                                            =
}

abstract class User {                            =
    public function getDisplayLabel() {
        return $this->username . “   ”;
    }
}

class GuestUser extends User inplements Persistence {
    use PersistentModel;
}

class AdminUser extends User inplements Persistence {
    use PersistentModel;
    public function getAdminRoleType() {
        ...;
    }
}
PHP5.4
O/R
関西PHP勉強会 php5.4つまみぐい
CLOSURE
関西PHP勉強会 php5.4つまみぐい
CALLABLE
call_user_func
php   > $fun = 'intval';
php   > echo call_user_func($fun, "0001abc"), "n";
1
php   > echo is_callable($fun), "n";
1
php   > echo is_string($fun), "n";
1


php > echo $fun("0001abc"), "n";
1
call_user_func                             array
php >   $obj = new Exception('hoge');
php >   $msg = [$obj, 'getMessage'];
php >   echo call_user_func($msg), "n";
hoge
php >   echo is_callable($msg), "n";
1
php >   echo is_array($msg), "n";
1


php > echo $msg(), "n";
hoge
php > echo $closure(), "n";   //




 string array
                               ↓
 is_callable
                                    Array
$THIS IN CLOSURE
PHP5.3
<?php
class CounterFactory {
    function __construct($init) {
        $this->init = $init;
    }
    function createCounter() {
        $c = 0;
        return function() use(&$c) {
            return $this->init + ($c++);
        };
    }
}
$fact = new CounterFactory(100);
$c1 = $fact->createCounter();
$c2 = $fact->createCounter();
echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n";
echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n";
echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";
PHP5.3
<?php
class CounterFactory {
    function __construct($init) {
        $this->init = $init;
    }
    function createCounter() {
        $c = 0;
        $self = $this;
        return function() use($self, &$c) {
            return $self->init + ($c++);
        };
    }
}
$fact = new CounterFactory(100);
$c1 = $fact->createCounter();
$c2 = $fact->createCounter();
echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n";
echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n";
echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";
self → Python
PHP5.4                               OK!
<?php
class CounterFactory {
    function __construct($init) {
        $this->init = $init;
    }
    function createCounter() {
        $c = 0;
        return function() use(&$c) {
            return $this->init + ($c++);
        };
    }
}
$fact = new CounterFactory(100);
$c1 = $fact->createCounter();
$c2 = $fact->createCounter();
echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n";
echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n";
echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";
<?php
class CounterFactory {
    function __construct($init) {
        $this->init = $init;
    }
    function createCounter() {
        $c = 0;
        return function() use(&$c) {
            return $this->init + ($c++);
        };
    }
}
$fact = new CounterFactory(100);
$c1 = $fact->createCounter();
$c2 = $fact->createCounter();
echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n";
echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n";
echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";

c1:100   <--   init=100   +   c=0
c1:101   <--   init=100   +   c=1
c2:100   <--   init=100   +   c=0
c2:101   <--   init=100   +   c=1
c2:102   <--   init=100   +   c=2
c1:102   <--   init=100   +   c=2
Javascript
$THIS
<?php
class CounterFactory {
    function __construct($init) {
        $this->init = $init;
    }
    function createCounter() {
        $c = 0;
        return function() use(&$c) {
            return $this->init + ($c++);
        };
    }
}
$fact = new CounterFactory(100);
$c1 = $fact->createCounter();
echo "c1:", $c1(), "n";
echo "c1:", $c1(), "n";
$c1 = $c1->bindTo(new CounterFactory(1000));
echo "c1:", $c1(), "n";
<?php
class CounterFactory {
    function __construct($init) {
        $this->init = $init;
    }
    function createCounter() {
        $c = 0;
        return function() use(&$c) {
            return $this->init + ($c++);
        };
    }
}
$fact = new CounterFactory(100);
$c1 = $fact->createCounter();
echo "c1:", $c1(), "n";
echo "c1:", $c1(), "n";
$c1 = $c1->bindTo(new CounterFactory(1000));
echo "c1:", $c1(), "n";


c1:100 <-- init=100 + c=0
c1:101 <-- init=100 + c=1
c1:1002 <-- init=1000 + c=2
CLOSURE

•   PHP5.4                       create_function

•   Javascript           this

•                    $this                $this



•

    →            PHP5.3 $self               bindTo        PHP5.4
                                                  $this
<?php                             <?php
class Hoge {                      class Hoge {
  function __construct($init) {     function __construct($init) {
    $this->init = $init;              $this->init = $init;
  }                                 }
  function x($n) {                  function x($n) {
    $tmp = [];                        return array_map(
    for($i=0; $i<$n; $i++) {             function() {
      $tmp[] = $this->init;                return $this->init;
    }                                    }, range(0,$n-1)
    return $tmp;                      );
  }                                 }
}                                 }

print_r((new Hoge(100))->x(3));   print_r((new Hoge(100))->x(3));
関西PHP勉強会 php5.4つまみぐい
• new


•       array
関西PHP勉強会 php5.4つまみぐい
PHP5.3
                PHP5.4                  OK


echo (new Exception("hoge"))->getMessage(), "n";
PHP5.3
                PHP5.4       OK


echo range(0, 9)[5], “n”;
PHP5.4.0RC1


php > echo (array(1, 2, 3))[0], "n";
Parse error: syntax error, unexpected '[', expecting ',' or ';'
in php shell code on line 1

php > echo (function($x){ return $x * 2; })(10), "n";
Parse error: syntax error, unexpected '(', expecting ',' or ';'
in php shell code on line 1
関西PHP勉強会 php5.4つまみぐい
<?=


<?=
PHP5.4

• PHP5.3

           5.2

 •


 • Phar

• PHP5.4
関西PHP勉強会 php5.4つまみぐい
PHP5.4

More Related Content

What's hot (20)

Smolder @Silex
Smolder @Silex
Jeen Lee
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
Webrtc mojo
Webrtc mojo
bpmedley
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
Shinya Ohyanagi
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
Mark Baker
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
julien pauli
 
Perl web frameworks
Perl web frameworks
diego_k
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11
Combell NV
 
Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
 
CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11
Combell NV
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
Mark Baker
 
Php functions
Php functions
JIGAR MAKHIJA
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기
Juwon Kim
 
Intro to PHP
Intro to PHP
Sandy Smith
 
PHP7 Presentation
PHP7 Presentation
David Sanchez
 
Intro to php
Intro to php
Sp Singh
 
Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18
Lar21
 
Zero to SOLID
Zero to SOLID
Vic Metcalfe
 
Smolder @Silex
Smolder @Silex
Jeen Lee
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
Webrtc mojo
Webrtc mojo
bpmedley
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
Shinya Ohyanagi
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
Mark Baker
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
julien pauli
 
Perl web frameworks
Perl web frameworks
diego_k
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11
Combell NV
 
Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
 
CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11
Combell NV
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
Mark Baker
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기
Juwon Kim
 
Intro to php
Intro to php
Sp Singh
 
Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18
Lar21
 

Viewers also liked (12)

PHP-Ninjaの裏側
PHP-Ninjaの裏側
Takayuki Miyauchi
 
CakePHP最新情報 PHPカンファレンス関西2012
CakePHP最新情報 PHPカンファレンス関西2012
ichikaway
 
VCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environment
Takayuki Miyauchi
 
オープンソース & オープンデータ
オープンソース & オープンデータ
Takayuki Miyauchi
 
FuelPHPをさわってみて
FuelPHPをさわってみて
Sotaro Omura
 
WordPress開発の最新事情
WordPress開発の最新事情
Takayuki Miyauchi
 
え?まだMAMPで消耗してんの?
え?まだMAMPで消耗してんの?
Takayuki Miyauchi
 
あらためてPHP5.3
あらためてPHP5.3
Masashi Shinbara
 
Cybozu Kintone x WordPress
Cybozu Kintone x WordPress
Takayuki Miyauchi
 
I love Automation
I love Automation
Takayuki Miyauchi
 
オープンソースによるイノベーションの継続
オープンソースによるイノベーションの継続
Takayuki Miyauchi
 
WordPress on HHVM + Hack
WordPress on HHVM + Hack
Takayuki Miyauchi
 
CakePHP最新情報 PHPカンファレンス関西2012
CakePHP最新情報 PHPカンファレンス関西2012
ichikaway
 
VCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environment
Takayuki Miyauchi
 
オープンソース & オープンデータ
オープンソース & オープンデータ
Takayuki Miyauchi
 
FuelPHPをさわってみて
FuelPHPをさわってみて
Sotaro Omura
 
WordPress開発の最新事情
WordPress開発の最新事情
Takayuki Miyauchi
 
え?まだMAMPで消耗してんの?
え?まだMAMPで消耗してんの?
Takayuki Miyauchi
 
オープンソースによるイノベーションの継続
オープンソースによるイノベーションの継続
Takayuki Miyauchi
 
Ad

Similar to 関西PHP勉強会 php5.4つまみぐい (20)

What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Advanced symfony Techniques
Advanced symfony Techniques
Kris Wallsmith
 
Fatc
Fatc
Wade Arnold
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Blog Hacks 2011
Blog Hacks 2011
Yusuke Wada
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
Building Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Apostrophe
Apostrophe
tompunk
 
Doctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
Michelangelo van Dam
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
Building Lithium Apps
Building Lithium Apps
Nate Abele
 
What's new with PHP7
What's new with PHP7
SWIFTotter Solutions
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2
Elizabeth Smith
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricks
Filip Golonka
 
Mojolicious
Mojolicious
Marcos Rebelo
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
Michelangelo van Dam
 
What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Advanced symfony Techniques
Advanced symfony Techniques
Kris Wallsmith
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
Building Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Apostrophe
Apostrophe
tompunk
 
Doctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
Michelangelo van Dam
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
Building Lithium Apps
Building Lithium Apps
Nate Abele
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2
Elizabeth Smith
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricks
Filip Golonka
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
Michelangelo van Dam
 
Ad

More from Hisateru Tanaka (19)

HTMLに学ぶ夫婦円満のコツ
HTMLに学ぶ夫婦円満のコツ
Hisateru Tanaka
 
とある事業の脱レガシー
とある事業の脱レガシー
Hisateru Tanaka
 
Yii Framework 2.0 いま求められるRAD標準とは #phpkansai
Yii Framework 2.0 いま求められるRAD標準とは #phpkansai
Hisateru Tanaka
 
第21回関西PHP勉強会 ReactPHPは もっと流行って欲しい #phpkansai
第21回関西PHP勉強会 ReactPHPは もっと流行って欲しい #phpkansai
Hisateru Tanaka
 
ダイクストラの構造化 プログラミングに学ぶ 結婚生活
ダイクストラの構造化 プログラミングに学ぶ 結婚生活
Hisateru Tanaka
 
PHPカンファレンス関西2014 Yii Framework 2.0 遅れてきた5番目のフレームワーク
PHPカンファレンス関西2014 Yii Framework 2.0 遅れてきた5番目のフレームワーク
Hisateru Tanaka
 
Grunt front-osaka-1-lt-tanaka
Grunt front-osaka-1-lt-tanaka
Hisateru Tanaka
 
Phpstormちょっといい話
Phpstormちょっといい話
Hisateru Tanaka
 
#phpmatsuri LT大会システムの中身
#phpmatsuri LT大会システムの中身
Hisateru Tanaka
 
&& || and or まぜるな危険
&& || and or まぜるな危険
Hisateru Tanaka
 
Phpcon kansani-2013-pinoco
Phpcon kansani-2013-pinoco
Hisateru Tanaka
 
はじめてのGit #gitkyoto
はじめてのGit #gitkyoto
Hisateru Tanaka
 
PhpStormを使おう --高槻からは快速急行が早くなります #jbugj
PhpStormを使おう --高槻からは快速急行が早くなります #jbugj
Hisateru Tanaka
 
いまどきのYiiフレームワーク
いまどきのYiiフレームワーク
Hisateru Tanaka
 
Kphpug beginners-2
Kphpug beginners-2
Hisateru Tanaka
 
Word pressのテーマは firephpでハックすれば 良かったのか
Word pressのテーマは firephpでハックすれば 良かったのか
Hisateru Tanaka
 
関西Php勉強会のlimeの話
関西Php勉強会のlimeの話
Hisateru Tanaka
 
Pinoco phptal-phpcon-kansai
Pinoco phptal-phpcon-kansai
Hisateru Tanaka
 
Yiiフレームワークを使ってみた
Yiiフレームワークを使ってみた
Hisateru Tanaka
 
HTMLに学ぶ夫婦円満のコツ
HTMLに学ぶ夫婦円満のコツ
Hisateru Tanaka
 
とある事業の脱レガシー
とある事業の脱レガシー
Hisateru Tanaka
 
Yii Framework 2.0 いま求められるRAD標準とは #phpkansai
Yii Framework 2.0 いま求められるRAD標準とは #phpkansai
Hisateru Tanaka
 
第21回関西PHP勉強会 ReactPHPは もっと流行って欲しい #phpkansai
第21回関西PHP勉強会 ReactPHPは もっと流行って欲しい #phpkansai
Hisateru Tanaka
 
ダイクストラの構造化 プログラミングに学ぶ 結婚生活
ダイクストラの構造化 プログラミングに学ぶ 結婚生活
Hisateru Tanaka
 
PHPカンファレンス関西2014 Yii Framework 2.0 遅れてきた5番目のフレームワーク
PHPカンファレンス関西2014 Yii Framework 2.0 遅れてきた5番目のフレームワーク
Hisateru Tanaka
 
Grunt front-osaka-1-lt-tanaka
Grunt front-osaka-1-lt-tanaka
Hisateru Tanaka
 
Phpstormちょっといい話
Phpstormちょっといい話
Hisateru Tanaka
 
#phpmatsuri LT大会システムの中身
#phpmatsuri LT大会システムの中身
Hisateru Tanaka
 
&& || and or まぜるな危険
&& || and or まぜるな危険
Hisateru Tanaka
 
Phpcon kansani-2013-pinoco
Phpcon kansani-2013-pinoco
Hisateru Tanaka
 
はじめてのGit #gitkyoto
はじめてのGit #gitkyoto
Hisateru Tanaka
 
PhpStormを使おう --高槻からは快速急行が早くなります #jbugj
PhpStormを使おう --高槻からは快速急行が早くなります #jbugj
Hisateru Tanaka
 
いまどきのYiiフレームワーク
いまどきのYiiフレームワーク
Hisateru Tanaka
 
Word pressのテーマは firephpでハックすれば 良かったのか
Word pressのテーマは firephpでハックすれば 良かったのか
Hisateru Tanaka
 
関西Php勉強会のlimeの話
関西Php勉強会のlimeの話
Hisateru Tanaka
 
Pinoco phptal-phpcon-kansai
Pinoco phptal-phpcon-kansai
Hisateru Tanaka
 
Yiiフレームワークを使ってみた
Yiiフレームワークを使ってみた
Hisateru Tanaka
 

Recently uploaded (20)

ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 

関西PHP勉強会 php5.4つまみぐい

  • 2. ABOUT ME • ( ) • @tanakahisateru • https://github.com/tanakahisateru • Firebug, FireCookie, jEdit • ...and Pinoco
  • 4. PHP5.4 • Array Short Syntax • Built-in Server • Trait • Closure •
  • 5. :
  • 6. PHP5.4 Graham ( @predominant ) :) http://tipshare.info/view/ 4ec326d04b2122ce49000000
  • 8. PHP 5.4 RC1 (2011/11/11) • http://www.php.net/archive/2011.php#id2011-11-11-1
  • 9. PHP PHP 5.4 http://www.1x1.jp/blog/ 2011/06/ try_new_php_without_update _current_version.html configure make
  • 10. Windows • http://windows.php.net/qa/ • Mac • XCode + MacPorts or Homebrew • Linux •
  • 11. % curl -o php-5.4.0RC1.tar.gz http://downloads.php.net/stas/ php-5.4.0RC1.tar.gz % tar xzf php-5.4.0RC1.tar.gz % cd php-5.4.0RC1 % ./configure --prefix=/opt/local/php/5.4 --bindir=/opt/local/bin --with-config-file-path=/opt/local/php/5.4/etc --with-config-file-scan-dir=/opt/local/php/5.4/var/db --mandir=/opt/local/php/5.4/share/man --infodir=/opt/local/php/5.4/share/info --program-suffix=-5.4 --with-apxs2=/opt/local/apache2/bin/apxs ( https://gist.github.com/1344162 ) % make
  • 12. (make install) sapi/cli/php configure PHP
  • 13. % sapi/cli/php -v PHP 5.4.0RC1 (cli) (built: Nov 23 2011 23:08:40) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2011 Zend Technologies % sapi/cli/php -a Interactive shell php >
  • 14. php > echo “Hello Worldn”; Hello World php > print_r(array_map(function($x){ return $x * 2; }, range(0,9))); Array ( [0] => 0 [1] => 2 [2] => 4 [3] => 6 [4] => 8 [5] => 10 [6] => 12 [7] => 14 [8] => 16 [9] => 18 ) : php > echo 0xff == 0b11111111, "n"; 1
  • 19. var $belongsTo = array( ! 'User' ); var $hasMany = array( 'Photo' => array( 'order' => 'number' ) ); var $belongsTo = [ ! 'User' ]; var $hasMany = [ 'Photo' => [ 'order' => 'number' ] ];
  • 20. $this->render('list', array( 'posts' => Post::find(array( 'limit' => Config::get('postsPerPage', array('context'=>'blog', 'default'=>10)), )) )); ? $this->render('list', [ 'posts' => Post::find([ 'limit' => Config::get('postsPerPage', ['context'=>'blog', 'default'=>10]), ]) ]);
  • 22. $this->render('list', array( 'posts' => Post::find(array( 'limit' => Config::get('postsPerPage', array('context'=>'blog', 'default'=>10)), )) )); $this->render('list', [ 'posts' => Post::find([ 'limit' => Config::get('postsPerPage', ['context'=>'blog', 'default'=>10]), ]) ]);
  • 23. $this->render('list', array( 'posts' => Post::find(array( 'limit' => Config::get('postsPerPage', array('context'=>'blog', 'default'=>10)), )) )); $this->render('list', [ 'posts' => Post::find([ 'limit' => Config::get('postsPerPage', ['context'=>'blog', 'default'=>10]), ]) ]); Array
  • 24. $this->render('list', array( 'posts' => Post::find(array( 'limit' => Config::get('postsPerPage', array('context'=>'blog', 'default'=>10)), )) )); $this->render('list', [ 'posts' => Post::find([ 'limit' => Config::get('postsPerPage', ['context'=>'blog', 'default'=>10]), ]) ]); [ ... ]
  • 25. ARRAY SHORT SYNTAX • → • • PHP • Array
  • 26. ARRAY SHORT SYNTAX • PHP array YAML • PHP
  • 29. % sapi/cli/php -S localhost:8080
  • 30. Javascript Flash file:// API → PHP5.4 • Apache • PHP
  • 31. .htaccess mod_rewrite
  • 32. PHP % sapi/cli/php -S localhost:8080 builtin-server.php
  • 33. list($path, $param) = array_merge( preg_split('/?/', $_SERVER['REQUEST_URI'], 2), ['', ''] ); if($path != '/' && (file_exists('app/webroot' . $path))) { header(sprintf('Location: http://%s/app/webroot%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])); exit; } else if($path != '/' && (file_exists('./' . $path))) { return false; } else { $_SERVER['PATH_INFO'] = $path; require 'app/webroot/index.php'; }
  • 34. % ~/php54/php-5.4.0RC1/sapi/cli/php -S localhost:8080 builtin-server.php
  • 36. PHP 5.4.0RC1 Development Server started at Thu Nov 24 02:11:37 2011 Listening on localhost:8080 Document root is /Users/tanakahisateru/Sites/cakephp2 Press Ctrl-C to quit. [Thu Nov 24 02:11:42 2011] ::1:63556 [200]: /app/webroot/css/cake.generic.css [Thu Nov 24 02:11:42 2011] ::1:63557 [200]: /app/webroot/img/cake.power.gif [Thu Nov 24 02:11:42 2011] ::1:63558 [200]: /app/webroot/img/cake.icon.png [Thu Nov 24 02:11:42 2011] ::1:63564 [200]: /app/webroot/favicon.ico
  • 37. MacPorts MySQL php.ini % ~/php54/php-5.4.0RC1/ sapi/cli/php -c ~/php54/ php-5.4.0RC1/ -S localhost:8080 builtin-server.php ~/php54/php-5.4.0RC1/php.ini [Pdo_mysql] pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock MySQL
  • 38. BUILT-IN SERVER • URL OK • Apache • PHP5.3 Apache mod_php PHP5.4
  • 39. TRAIT
  • 40. NO.1
  • 41. TRAIT • • Ruby mixin • PHP (instanceof ) •
  • 43. 1 INCLUDE / REQUIRE • • HTML • /
  • 44. 2 • • • class AppModel extends Model class GuestUser extends AppModel class AdminUser extends AppModel User
  • 45. class AppModel extends Model { } class GuestUser extends AppModel { public function getDisplayLabel() { ...; } } !! class AdminUser extends AppModel { public function getDisplayLabel() { ...; } public function getAdminRioleType() { ...; } }
  • 46. class AppModel extends Model { public function getDisplayLabel() { ...; } } class GuestUser extends AppModel { } class AdminUser extends AppModel { public function getAdminRioleType() { ...; } }
  • 47. class AppModel extends Model { public function getDisplayLabel() { return $this->username . “ ”; } } class GuestUser extends AppModel { } class AdminUser extends AppModel { public function getAdminRoleType() { ...; } } class Comment extends AppModel { // username ← }
  • 48. UserModel.inc public function getDisplayLabel() { return $this->username . “ ”; } class GuestUser extends AppModel { require ‘UserModel.inc’; } class AdminUser extends AppModel { require ‘UserModel.inc’; public function getAdminRoleType() { ...; } } class Comment extends AppModel { } ... require = orz
  • 49. trait UserModel { public function getDisplayLabel() { return $this->username . “ ”; } } class GuestUser extends AppModel { use UserModel; } class AdminUser extends AppModel { use UserModel; public function getAdminRoleType() { ...; } } class Comment extends AppModel { }
  • 51. trait PersistentModel { public function save() { } = } abstract class User { = public function getDisplayLabel() { return $this->username . “ ”; } } class GuestUser extends User inplements Persistence { use PersistentModel; } class AdminUser extends User inplements Persistence { use PersistentModel; public function getAdminRoleType() { ...; } }
  • 57. call_user_func php > $fun = 'intval'; php > echo call_user_func($fun, "0001abc"), "n"; 1 php > echo is_callable($fun), "n"; 1 php > echo is_string($fun), "n"; 1 php > echo $fun("0001abc"), "n"; 1
  • 58. call_user_func array php > $obj = new Exception('hoge'); php > $msg = [$obj, 'getMessage']; php > echo call_user_func($msg), "n"; hoge php > echo is_callable($msg), "n"; 1 php > echo is_array($msg), "n"; 1 php > echo $msg(), "n"; hoge
  • 59. php > echo $closure(), "n"; // string array ↓ is_callable Array
  • 61. PHP5.3 <?php class CounterFactory { function __construct($init) { $this->init = $init; } function createCounter() { $c = 0; return function() use(&$c) { return $this->init + ($c++); }; } } $fact = new CounterFactory(100); $c1 = $fact->createCounter(); $c2 = $fact->createCounter(); echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";
  • 62. PHP5.3 <?php class CounterFactory { function __construct($init) { $this->init = $init; } function createCounter() { $c = 0; $self = $this; return function() use($self, &$c) { return $self->init + ($c++); }; } } $fact = new CounterFactory(100); $c1 = $fact->createCounter(); $c2 = $fact->createCounter(); echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";
  • 64. PHP5.4 OK! <?php class CounterFactory { function __construct($init) { $this->init = $init; } function createCounter() { $c = 0; return function() use(&$c) { return $this->init + ($c++); }; } } $fact = new CounterFactory(100); $c1 = $fact->createCounter(); $c2 = $fact->createCounter(); echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n";
  • 65. <?php class CounterFactory { function __construct($init) { $this->init = $init; } function createCounter() { $c = 0; return function() use(&$c) { return $this->init + ($c++); }; } } $fact = new CounterFactory(100); $c1 = $fact->createCounter(); $c2 = $fact->createCounter(); echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c2:", $c2(), "n"; echo "c1:", $c1(), "n"; c1:100 <-- init=100 + c=0 c1:101 <-- init=100 + c=1 c2:100 <-- init=100 + c=0 c2:101 <-- init=100 + c=1 c2:102 <-- init=100 + c=2 c1:102 <-- init=100 + c=2
  • 67. $THIS <?php class CounterFactory { function __construct($init) { $this->init = $init; } function createCounter() { $c = 0; return function() use(&$c) { return $this->init + ($c++); }; } } $fact = new CounterFactory(100); $c1 = $fact->createCounter(); echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n"; $c1 = $c1->bindTo(new CounterFactory(1000)); echo "c1:", $c1(), "n";
  • 68. <?php class CounterFactory { function __construct($init) { $this->init = $init; } function createCounter() { $c = 0; return function() use(&$c) { return $this->init + ($c++); }; } } $fact = new CounterFactory(100); $c1 = $fact->createCounter(); echo "c1:", $c1(), "n"; echo "c1:", $c1(), "n"; $c1 = $c1->bindTo(new CounterFactory(1000)); echo "c1:", $c1(), "n"; c1:100 <-- init=100 + c=0 c1:101 <-- init=100 + c=1 c1:1002 <-- init=1000 + c=2
  • 69. CLOSURE • PHP5.4 create_function • Javascript this • $this $this • → PHP5.3 $self bindTo PHP5.4 $this
  • 70. <?php <?php class Hoge { class Hoge { function __construct($init) { function __construct($init) { $this->init = $init; $this->init = $init; } } function x($n) { function x($n) { $tmp = []; return array_map( for($i=0; $i<$n; $i++) { function() { $tmp[] = $this->init; return $this->init; } }, range(0,$n-1) return $tmp; ); } } } } print_r((new Hoge(100))->x(3)); print_r((new Hoge(100))->x(3));
  • 72. • new • array
  • 74. PHP5.3 PHP5.4 OK echo (new Exception("hoge"))->getMessage(), "n";
  • 75. PHP5.3 PHP5.4 OK echo range(0, 9)[5], “n”;
  • 76. PHP5.4.0RC1 php > echo (array(1, 2, 3))[0], "n"; Parse error: syntax error, unexpected '[', expecting ',' or ';' in php shell code on line 1 php > echo (function($x){ return $x * 2; })(10), "n"; Parse error: syntax error, unexpected '(', expecting ',' or ';' in php shell code on line 1
  • 79. PHP5.4 • PHP5.3 5.2 • • Phar • PHP5.4