It so happened that last September I switched to a company where PHP 7 was the main backend development language. Before that, the technologies I worked with were limited to C #, ASP.NET, Javascript (JQuery, Angular 1.x, Typescript), MS SQL, IIS and Windows Server. Now there was immersion in a new stack. This article is not just another attack on the fan to support holivar. I will try to note what seemed unusual or unusual. The article is addressed to .net developers, but I hope that the PHP community will be interested as well.

Let's start with the session
ASP.NET supports several modes of operation with the session. The simplest and standard mode of in-proc: session data is stored in the process memory, in the application domain. From any page, you can access Session ["key"] and retrieve or save data. In PHP, you can distinguish two standard mechanisms for working with the session - files and memcached. When working with sessions, the main difference between ASP.NET and PHP is: persistence. ASP.NET is an application that runs for a long time. This application has a stack, a heap, common static variables. Each request is a new thread within the overall process. Requests can easily interact through a shared memory process. PHP, on the contrary, is inherently closer to the stateless nature of HTTP. Each request is a new short-lived process. In the memory of the process, nothing remains between the requests, as well as the process itself. You can, of course, transfer objects through shared memory, but this is not particularly accepted. It is better to store data in files, database and memory using tools such as memcached. Through
session_set_save_handler()
you can store sessions anywhere.
Syntax, typing and variables
On the one hand, the syntax is C-like and does not cause any obvious confusion, like, for example, Python or Clojure syntax. On the other hand, in C #, I’m used to the fact that there’s a point and it’s for everything. In PHP, to access members of an instance of a class, use
->
(arrow, T_OBJECT_OPERATOR). To access static members and constants, use
::
(double colon,
Scope Resolution Operator ). Constantly confused, but then used.
')
Things are worse with variables. They are untyped, they can not be initialized, there is no start announcement.
<?php
This is a completely valid code. As you may have noticed, $ is used before the name, at first I forgot about it)
There are some unusual things in PHP. For example, variable variables:
<?php $a = 'hello'; $$a = 'world';
Comparison of lines, numbers, objects.
C # initially has strict comparison and type conversion policies. Unfortunately, PHP has a number of flaws that simplify life on simple projects, but lead to the fact that the usual comparison is very often puzzling. In the
office. the dock is written like this:
$ a == $ b TRUE if $ a is equal to $ b after type juggling .
The problem is that not many people know the rules for juggling by heart and
they may not be obvious .
Collections
In .net there are dozens of ready-made types and interfaces of collections, depending on the behavior that we need, we choose Queue or ConcurrentDictionary, IList or Hashtable. At interviews skip questions about the types of collections, about the differences of interfaces and so on.
In PHP, there is only an associative array (a set of key-value pairs); there are no other collections.
From the documentation:
This type is optimized in several ways, so you can use it as an array itself, a list (vector), a hash table (which is a map implementation), a dictionary, a collection, a stack, a queue, and possibly something else. Since the value of the array can be another PHP array, you can also create trees and multi-dimensional arrays.
UPD from
oxidmod :
there are data structures in SPL.
Multithreading
You are used to multithreading in .net. A rare interview does without questions about threads, pool, lock, async-await, etc. There is no multithreading and asynchrony in PHP *. I would be glad if you share your experience in asynchronous PHP (web) in the comments.
* PHP has pthreads, PHP has projects like ReactPHP. But if we talk about web-projects, I have repeatedly heard the opinion that PHP does not involve asynchronous operations.
Instruments
Visual Studio is one of the most powerful arguments in favor of dotnet. Free IDE with the richest functionality is a good help in the work. Add resharper and static typing here and get a handy set for development, project navigation and refactoring. In addition, recently released Rider, which in some ways even exceeds the usual Visual Studio. But windows-only .net-world was a strong brake on the development of the platform and tools around. I hope that .net core will become a new platform driver.
If we talk about PHP, then PHPStorm from the same Jetbrains has become the main medium at the moment. Strong typing only penetrates PHP7, and this complicates refactoring and static error checking. Various innovations in the field of type-hinting in future versions of the language will make the toolkit more powerful and better.
It should also be noted that PHP was originally developed for * nix-platforms and most infrastructure projects, too, all this makes the use of such things as docker, mysql, nosql easier and more natural. In addition, such projects are often free, which provides a wide distribution. Most PHP projects do not need windows solutions at all.
Books
Here everything is bad with PHP (in Russian). Since the language radically changes the approaches, then buying and reading books about PHP 5.x is a waste of time and money. According to version 7 for ozone now three books. I bought myself
Koterov and generally satisfied. And I am waiting for the
fifth edition of the book on patterns and approaches in PHP (the output was once again postponed, now for the spring of 2018). The first can be compared with Troelson (in size and depth). The second is very praised, as will come out - be sure to read. Top of my books on .net - Albahari, Richter, Tsvalina and Esposito. It may be worthwhile to wait in the near future for more fundamental books on PHP7, but right now I have not found any relevant books comparable in depth to those indicated. I would be glad if you tell me!
Projects
Dotnet is a general application framework. You can write desktop applications, mobile applications, websites, webapps, etc. on it. There are even developments such as Netduino and the .NET Micro Framework. PHP is still more about the web (or some background tasks based on the same codebase as the main web project).
In fact, many types of tasks are implemented in PHP: parsers, chatbots, and more. But the first contact with PHP for most developers is web projects.
And it is in the web that PHP is presented much more widely, if you count it individually, then PHP is likely to remain the leader for a long time. Moreover, PHP is unlikely to turn into an outsider: a huge number of PHP sites are well-known projects with a large audience: vk, avito, badoo.
Language development
Here, it seems to me, the fundamental difference. PHP is driven by the community. New features arrive in the form of RFC, they are discussed, they are voted for, included in the release plan, etc. Dontnet has an owner - Microsoft. Now they have made a pivot in the direction of the open source, they have always listened to the community, but decisions are made quite authoritarian. I do not know which option is better, there are pluses here and there. Development is more consistent and predictable. on the other hand, the feature may lie without movement forever, since the committee believes that right now it does not meet the needs of the language.
We see how C # and .Net are developing. Personally, I started with 1.1 - I remember how generics appeared, linq, TPL. It was cool. But somehow it fit into the general outline. The first dotnet initially looked at the finished Java and the approaches adopted there. C # hasn't changed dramatically, I think.
PHP has a more tortuous path (
read on Habré ). Language was originally distinguished by ease of development, maximum friendliness to poor-quality code. It was possible to make a fairly complicated website quickly and without special knowledge. A lot of people without any special skills reached into web development. During this period, thousands of projects started, which we somehow use today. It is difficult to overestimate the contribution of PHP in the development of the web. The industry grew, money appeared, experts appeared, there was a need for refactoring of legacy projects. And it became clear that the original code could not be maintained by methods known in the industry. As a result, PHP made a turn towards good practices: OOP, typing. But still left some of the former lightness.
Job
I always thought that the salary in the dotnet-world is higher, and this, in general, is true, judging by the average for the hospital. But there is one caveat: the market is sorely lacking PHP developers who know what OOP is, patterns, SOLID, and know how to use it. As I wrote projects, they grew and were overwhelmed with money and a bunch of code, frameworks appeared on which new projects could be started (Symfony, Yii, Laravel). All this led to an increase in demand. And large successful companies are willing to pay good money. As a result, a PHP developer can now claim even big money at a comparable skill level.
Conclusion
In general, the language is more “magical” (magic methods, juggling when comparing) and forgives many mistakes. About MS SQL vs MySQL, you can write a bunch of the same posts. There are much more significant differences and interesting features than I have already indicated: point concatenation, treitures, interpolation of strings in double quotes, etc. I have chosen only a few - the rest can be discussed in the comments.
I'm glad to see that modern PHP 7 looks more and more like C # known to me! Colleagues, who still treats with disdain for PHP - I responsibly declare that it is a completely different language and you can safely transfer your OOP approaches to projects on it.
Learn new languages and technologies! Be the best version of yourself!