Yii, PHP and frameworks

Alexander Makarov

Yii core team

https://slides.rmcreative.ru/2019/php-serbia-yii-php-frameworks/

About me

We are going to talk about

  • PHP.
  • Where is it heading to.
  • What to learn?
  • Which framework to choose next?
  • Yii.

Let's start with

PHP

Overall PHP usage and popularity declines to some degree but it is still one of the most popular languages.

Where is PHP heading to?

But first a bit about languages in general

What's the difference between languages?

Users

  • Novice.
  • Specialist.
  • Professional.
  • ...

There are almost no all-stars IT-teams when it comes to real business. You need a language for novices.

Novices need

  • Frames (guidelines, limitations).
  • Strictness.
  • Examples.
  • Java is for novices.
  • Python is for experienced.
  • JavaScript...

Features are less important

We're more assembling rather than developing except domain.
Need performance? Do it as golang micro-service.

Paradigm is important!

PHP improved over years

Composer PHP stats https://blog.packagist.com/php-versions-stats-2018-2-edition/

PHP 7.0

  • Performance.
  • More exceptions.
  • Return types and scalar typehints.
  • assert().
  • Security.
  • phpdoc is always cached (annotations).

PHP 7.1

  • nullable types.
  • void return.
  • Constant visibility (private, protected, public).
  • pcntl_async_signals.

PHP 7.2

  • object as typehint.
  • More security.
  • Syntactic sugar.

PHP 7.3

  • is_countable().
  • Syntactic sugar.

PHP 7.4

  • Performance.
  • Syntactic sugar.
  • Typed properties.
  • Improved type variance.

Is PHP okay?

It is!

  • Somewhere between "for novice" and "for fun".
  • Frameworks could shift above position.
  • Teamleads and tools are watching.
  • Allows prototyping fast.
  • Infrastructure is great! Composer.
  • Stateless by default.
  • Good for domain.

What to learn?

Learn what you can use anywhere

  • OOP/OOD. Check yourself with cohesion/coupling.
  • HTTP/HTTPS/REST.
  • Security.
  • SQL.
  • CAP (Consistency-Availability-Partition Tolerance).
  • Basic understanding of algorithm complexity.
  • Refactoring.
  • Linux.

You still should learn the framework you use!

Business needs more than that...

  • Predictability.
  • Performance.
  • Adequate cost.
  • Ability to express yourself clearly.
  • Ability to write dirty code quickly.
  • Ability to estimate.
  • Desire to learn new things.

Which framework to choose next?

What do we have?

  • Laravel.
  • Symfony.
  • Yii 2.
  • CakePHP.
  • CodeIgniter.
  • Zend Framework.
  • reactphp.
  • Phalcon.
  • FuelPHP.
  • Slim, F3, ...

Laravel

  • Best marketing. Most popular framework nowadays.
  • Secret priorities similar to Apple.
  • Questionable community relations.
  • It's mostly alright.

Symfony

  • Strong limitations.
  • Performance issues are being solved by caching and compiling (extreme case - OroCRM).
  • It better if cache works well. Debug isn't easy sometimes. There are many layers.
  • Style is similar to Java and Spring.
  • Since recently following Laravel features :(

Zend Framework

Similar to Symfony but with different style.

Becoming Laminas soon.

Phalcon

  • Way better perforance.
  • Can't dig into it easily. It is PECL.

ReactPHP

Great for async daemons.

If you want a web-site...

  • Wordpress.
  • Drupal.
  • ...

Some studios create their own CMS with frameworks.

What do you really need from a framework?

It should be enjoyable.

What about no framework approach?

Do you have enough experience and time?

  • You'll build a framework anyway.
  • Each library is OK by itself but how about 10 libraries used together?
  • How to teach your team?
  • Deadlines... yesterday?

Try it. We succeeded in making a framework ;)

Don't get stuck with a single language or framework

  • PHP MVC.
  • Rapid development.
  • You can get from MVP to support and development.
  • Lots of features out of the box.
  • Flexible and pragmatic.
  • Allows taking shortcuts.
  • Non-commercial.

Originally created by Qiang Xue in 2008 based on his Prado framework (2004).

Yii 2 was released in 2014.

Some stats

  • Slack, 1500 users.
  • 500 projects at YiiPowered.
  • 12852 Github stars.
  • 31767 Facebook group members.

Yii values

  1. Be Practical
    • High Performance
    • Sensible Defaults and Flexibility
    • Be practice-oriented
  2. Be Helpful
    • Be simple
    • Be explicit
    • Be consistent

Same as with every framework Yii has its pros and cons.

  • RAD
  • Not too strict
  • Thin abstractions, sequential, good naming. Easy to read and debug.
  • Performance. Works great without cache.
  • Gii
  • Grids and data providers
  • Docs
  • ...

Yii 2.0 mistakes

Tried to handle too much

Got too much into the core.

  • jQuery.
  • PJAX.
  • CAPTCHA.
  • Masked input.
  • More clientside :(

Tried to fix PHP with magic.

Inheritance :(

Handled errors PHP way.

We haven't used many PSRs

They were mostly accepted after framework release. Backwards compatibility...

Old-style architecture.

next?

Yii 3

  • Set of packages (log, di, i18n etc.) + default application.
  • Allow both "classic" MVC and DDD.
  • SOLID, GRASP etc.
  • PSRs (HTTP request/response, middlewares, container, events).
  • Strict types.
  • Keep most good things from Yii 2.
  • Kill most of inheritance
  • Swoole / RoadRunner

We need your help!

Questions time!