SlideShare a Scribd company logo
UNKNOWN FEATURES OF
PHP
or less known ;)
ABOUT ME
CERTIFIED
PHP ENGINEER
CERTIFIED
A R C H I T E CT
2
Łukasz Witczak
10+ yrs experience
Unknown features of PHP
STRICTTYPED PHP?
IS IT POSSIBLETO WRITE
STRICTLYTYPED PHP CODE?
Never trust accepted answer at stackoverflow
STATIC/DYNAMIC
STRICT/WEAK?
• Static/Dynamic typing is about when type
information is aquired (at compiletime or at
runtime)
• Strong/Weak typing is about how strictly types
are distinguished (e.g. whether the language tries
to do implicit conversion from strings to
numbers).
WEAKTYPING AND STRICT
TYPING
• Fully strict type checking where no conversion happens (Go,
Facebook's Hack)
• Widening primitive type checking where “safe” conversions
happen (Java, Pascal, PHP Objects).
• Weak type checking which all conversions are allowed, with
possible warnings raised (which is used to a limited extent by C,
C#, C++ andVisual Basic, PHP scalars?)
“DESPITE THEIR PRODUCTIVITY
ADVANTAGES, DYNAMIC
LANGUAGES MAY NOT BE THE BEST
CHOICES FOR ALL APPLICATIONS,
PARTICULARLY FOR VERY LARGE
CODE BASES AND HIGH-
PERFORMANCE APPLICATIONS.”
http://docs.zephir-lang.com/en/latest/motivation.html#statically-typed-
versus-dynamically-typed-languages
TYPE HINTING PHP 5+
TYPE HINTING PHP7
SCALARTYPE HINTS
FOR PHP 5.4+
• string
• integer, int
• float, double
• boolean, bool
• resource
https://pecl.php.net/package/strict
LIMITATIONS
• “Internal functions cannot use strict hints, only user
code is supported.”
• “Because the parser detects scalar hints as classes,
they cannot have default values.” This was written before we knew that
PHP7 would get strict parameter and
return typing.

The best thing to do now is probably
make this a close approximation of
compatibility for PHP5 ... I'm super
busy right now and this isn't really a
priority …
–Joe Watkins
“ I'm super busy right now and this isn't really a
priority ...”
FUTURE
SPL_TYPES
http://php.net/manual/en/intro.spl-types.php
“This extension aims at helping people making PHP a
stronger typed language and can be a good alternative
to scalar type hinting.”
SPL_TYPES
Unknown features of PHP
Unknown features of PHP
demo?
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
SPL_TYPES
• Total downloads: 53,633
ZEPHIR
Zephir, an open source, high-level language designed to ease the
creation and maintainability of extensions for PHP with a focus on type
and memory safety.
ZEPHIR STATICTYPES
• boolean A boolean expresses a truth value. It can be either ‘true’ or ‘false’.
• integer Signed integers.At least 16 bits in size.
• unsigned integer Unsigned integers.At least 16 bits in size.
• char Smallest addressable unit of the machine that can contain basic character set.
• unsigned char Same size as char, but guaranteed to be unsigned.
• long Long signed integer type.At least 32 bits in size.
• unsigned long Same as long, but unsigned.
• float/double Double precision floating-point type.The size is platform-dependent.
• string A string is series of characters, where a character is the same as a byte.
• array An structure that can be used as hash, map, dictionary, collection, stack, etc.
ZEPHIR UNSIGNED INT
ZEPHIR CHAR AND STRING
ASYNCHRONOUS PHP
cooperative multitasking
Unknown features of PHP
SYNCHRONOUS
Tasks
Time
0 150 300 450 600
Task #1 Task #2 Task #3
ASYNCHRONOUS
Tasks
Time [ms]
0 75 150 225 300
Task #1 Task #2 Task #3
NODE.JS
Unknown features of PHP
EVENT-DRIVEN, NON-
BLOCKING I/O WITH PHP
Unknown features of PHP
pond 3mln pobrań promise
• StreamSelectLoop - out of the box
• LibEventLoop -This uses the libevent pecl extension with a
number of system-specific backends (epoll, kqueue).
• LibEvLoop -This uses the libev pecl extension (github). It
supports the same backends as libevent.
• ExtEventLoop -This uses the event pecl extension. It
supports the same backends as libevent
loop
by Marc J. Schmidt
• http://marcjschmidt.de/blog/2014/02/08/php-
high-performance.html
• https://github.com/php-pm/php-pmLibEvLoop
• http://reactphp.org/
• https://github.com/reactphp
resources
https://github.com/ratchetphp/Ratchet
ratchetphp/Ratchet
Ratchet is a loosely coupled PHP library providing developers with
tools to create real time, bi-directional applications between clients
and servers over WebSockets.
http://socketo.me/
• Supports the RFC6455, HyBi-10+, and Hixie76 protocol
versions (at the same time)
• Tested on Chrome 13+, Firefox 6+, Safari 5+, iOS 4.2+, IE 8+
• Ratchet passes the Autobahn Testsuite (non-binary
messages)
https://github.com/nrk/predis-async
Predis/Async
https://github.com/bixuehujin/reactphp-mysql
react/mysql
• mysql (with non blocking I/O) driver for
reactphp,
• It is written in pure PHP - implemented the
mysql protocol.
react/mysql
• Installs: 530
• Stars: 58
• Watchers: 11
• Forks: 13
• Open Issues: 3
react/mysql
https://github.com/reactphp/filesystem
react/filesystem
• Evented filesystem access utilising
asyncronous POSIX I/O by means of
libEIO C library
• requires http://php.net/eio extension
react/filesystem
react/filesystem
• Installs: 1 014
• Dependents: 2
• Stars: 33
• Watchers: 10
• Forks: 7
• Open Issues: 5
filesystem non-blocking I/O
HACK LANG
• Async,Await,Awaitable
HACK LANG
HACK LANG
od hhvm 3.6 - obecnie hhvm 3.10
ASYNC DB QUERIES
ASYNC MYSQL
mysqli::reap_async_query
mysqli_reap_async_query
Unknown features of PHP
ASYNC POSTGRESQL
ASYNC HTTP
CURL_MULTI
Unknown features of PHP
BUZZ
BUZZMULTI
BUZZVS BUZZMULTI
Time[ms]
0
1250
2500
3750
5000
Sync Multi
Trudność w gromadzeniu requestów
GUZZLE 5
END OF SCRIPT
http://www.rfc-editor.org/rfc/rfc1945.txt 200
http://www.rfc-editor.org/rfc/rfc7540.txt 200
http://www.rfc-editor.org/rfc/rfc2068.txt 200
composer require “guzzlehttp/guzzle:~5.3”
THREADS
Unknown features of PHP
YES!
PHP Threads…
…and NOT
pcntl_fork
Unknown features of PHP
https://pecl.php.net/package/pthreads
https://github.com/krakjoe/pthreads
http://php.net/pthreads
PTHREADS
• Object Orientated (like Java)
• Easy to use an safety built in (no MUTEX)
• High level implementation of POSIX threads
• Well documented
PTHREADS EXAMPLE
PTHREADS
• Stable since 2013-09-08 (0.0.45)
• Over 163,000 downloads (from PECL)
• Heavily developed: (35 releases)
• Mature
Unknown features of PHP
PTHREADS
• http://pthreads.org/
• https://gist.github.com/krakjoe/9384409
• https://gist.github.com/krakjoe/6437782
read first
PTHREADS
Not for web
–Joe Watkins
“(…)you can't use pthreads safely and sensibly
anywhere but CLI.”
PTHREADS
PHP-CLI YES!
THREDS ARE HARD
• https://web.stanford.edu/~ouster/cgi-bin/papers/
threads.pdf
Unknown features of PHP
OPERATOR OVERLOADING
Unknown features of PHP
Unknown features of PHP
OPERATOR OVERLOADING IN PHP
EXTENSIONS
OPERATOR OVERLOADING IN PHP
EXTENSIONS
THANKYOU
https://joind.in/16171
@woocashw
Unknown features of PHP

More Related Content

ODP
PPTX
Week 8 intro to python
PPTX
Semana Interop: Trabalhando com IronPython e com Ironruby
PDF
Number of Computer Languages = 3
PPTX
FFMS2: Indexing, Edge Cases, and Insanity
PDF
Vimeo and Open Source (SMPTE Forum 2015)
PDF
NLP using JavaScript Natural Library
PDF
Beyond JSON - An Introduction to FlatBuffers
Week 8 intro to python
Semana Interop: Trabalhando com IronPython e com Ironruby
Number of Computer Languages = 3
FFMS2: Indexing, Edge Cases, and Insanity
Vimeo and Open Source (SMPTE Forum 2015)
NLP using JavaScript Natural Library
Beyond JSON - An Introduction to FlatBuffers

What's hot (10)

PPTX
Languages formanandmachine
PPTX
NLP techniques for log analysis
PPT
Python Intro For Managers
PDF
NDC London 2014: Erlang Patterns Matching Business Needs
PPTX
Using unicode with php
PPTX
Static typing vs dynamic typing languages
PDF
Programming Languages #devcon2013
PDF
Polyglot Architecture: A Rational Approach to Software Design
PDF
Static vs dynamic types
Languages formanandmachine
NLP techniques for log analysis
Python Intro For Managers
NDC London 2014: Erlang Patterns Matching Business Needs
Using unicode with php
Static typing vs dynamic typing languages
Programming Languages #devcon2013
Polyglot Architecture: A Rational Approach to Software Design
Static vs dynamic types
Ad

Similar to Unknown features of PHP (20)

PPTX
Blazingly-Fast:Introduction to Apache Fury Serialization
PDF
State of Crypto in Python
PPTX
haXe - One codebase to rule'em all
PPTX
Api crash
PPTX
Api crash
PPTX
Api crash
PPTX
Api crash
PPTX
Api crash
PPTX
Api crash
PPTX
Api crash
PDF
State of Crypto in Python (OSCON)
PDF
The ES6 Conundrum - All Things Open 2015
PPTX
Interoperable PHP
PPTX
A deep dive into python and it's position in the programming landscape.pptx
PPTX
Introduction to Python Programming
PPTX
Putting Compilers to Work
PDF
Smart Signatures—Experiments in Authentication (Stanford BPASE 2018 final)
PDF
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
RTF
Hack language
PPTX
Php internal architecture
Blazingly-Fast:Introduction to Apache Fury Serialization
State of Crypto in Python
haXe - One codebase to rule'em all
Api crash
Api crash
Api crash
Api crash
Api crash
Api crash
Api crash
State of Crypto in Python (OSCON)
The ES6 Conundrum - All Things Open 2015
Interoperable PHP
A deep dive into python and it's position in the programming landscape.pptx
Introduction to Python Programming
Putting Compilers to Work
Smart Signatures—Experiments in Authentication (Stanford BPASE 2018 final)
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
Hack language
Php internal architecture
Ad

Recently uploaded (20)

PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPT
tcp ip networks nd ip layering assotred slides
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
artificial intelligence overview of it and more
PPTX
Introduction to Information and Communication Technology
PPTX
E -tech empowerment technologies PowerPoint
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
Introduction to the IoT system, how the IoT system works
SASE Traffic Flow - ZTNA Connector-1.pdf
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Tenda Login Guide: Access Your Router in 5 Easy Steps
Sims 4 Historia para lo sims 4 para jugar
The Internet -By the Numbers, Sri Lanka Edition
Paper PDF World Game (s) Great Redesign.pdf
presentation_pfe-universite-molay-seltan.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
Introuction about WHO-FIC in ICD-10.pptx
Slides PPTX World Game (s) Eco Economic Epochs.pptx
tcp ip networks nd ip layering assotred slides
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
artificial intelligence overview of it and more
Introduction to Information and Communication Technology
E -tech empowerment technologies PowerPoint
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
RPKI Status Update, presented by Makito Lay at IDNOG 10
Introduction to the IoT system, how the IoT system works

Unknown features of PHP