Learning PHP for a C++/C#/x86 Assembly coder?

A

Anonymous

Guest
Hi!

I'm new to the forums and to PHP, and although there's a long way to go for me, I wanted to get an idea how hard things might be for someone who's previously well-versed in C++/C# and also x86 Assembly language. I don't see many similarities in PHP just yet, but maybe that's not a bad thing - it's just something that may help me out.

I'd love to hear your thoughts.
 
PHP was my first language that I used on backend.
Now I am using C#. I still use the PHP for some simple scripts, but to be honest I don't see any good reason to learn php after c#.
Each version of php is getting more similar to java/c#, you can control the types if variables much more, but still can't force what you have in arrays or assign string to an integer variable that allow you to write the code inconsistency. That was the reason why I decide to rewrite one of my project from php to dotnet.
Second main difference is that the php is interpreted language, so you can create a textarea field with a php code and execute it on the server. Sometimes that is good (you can easly install plugins) but there is a lot of disadvantages, ie: someone may upload a script and execute it.
PHP is easy to run and learn, and the community is large, but this language have many limitations (ie there is no support for multi threading). It is great for small or medium projects, but if you want to create a large project you should choose different technology like dotnet or java
 
matthew92 said:
Hi!

I'm new to the forums and to PHP, and although there's a long way to go for me, I wanted to get an idea how hard things might be for someone who's previously well-versed in C++/C# and also x86 Assembly language. I don't see many similarities in PHP just yet, but maybe that's not a bad thing - it's just something that may help me out.

I'd love to hear your thoughts.

It's just another programming language. You have variables. You have functions. You can specify function parameters to pass by reference (something like a pointer but not as useful) and you can actually assign a var to share a reference with another, which is super handy. You can recurse or iterate. You cannot use a variable or call a function unless it was declared on an earlier line either in the same file or in the include chain, or unless it appears in a class (from a function on line 22 inside a class, you may call a function defined on line 368 inside the same class). Most of the built-in functions which want a callback function want you to give the callback's name as a string.

Namespaces are a real kludge. Do not waste your time.

I think the weirdest thing is the way any function may return two or more types, such as NULL or BOOLEAN or STRING depending on error type or level or count. You will find yourself writing lots of crazy validations like: if ( isset( $var ) && ( $var !== null ) && is_string( $var ) ) in which you must place your output tests such as if ( $var === 'somevalue' ). If you do not care which error occurred you can simplify to if ( $var && is_string( $var ) ) where you expected string output. So it is typed but not strongly, and it flaunts it recklessly.

I was just reminded earlier today that variable scope is very wonky. I used to do everything in the $_GLOBALS array, then wondered why when I read something in the manual about $_GLOBALS being deprecated, then came to a point where: If your var is globally scoped and you want to use it in a function, then you must redeclare it in your function via a globals keyword. That is not good enough if you call a function which calls that function though - every function down the line must redeclare that var with the globals keyword. The new thing is apparently to declare classes and make all the global vars and functions (which you want to use from anywhere) static.

Most syntax should be familiar if you program in ANSI C. PHP just has quirks. The manual is at php.net.
 
tekmunkey said:
You cannot use a variable or call a function unless it was declared on an earlier line either in the same file or in the include chain, or unless it appears in a class (from a function on line 22 inside a class, you may call a function defined on line 368 inside the same class).
PHP have some "funny" possibility that you can call a class that wasn't declared in the include chain. I am talking about autoloader, when you trying to use some class and you use its namespace (if it's not in root namespace), then the autoloader try to include the file with the class based on the PSR-0 or PRS-4 implementation.
More here: https://www.php.net/manual/en/function.spl-autoload.php
PHP is sometimes weird language where you can do something that should be impossible, like changing types whenever you want :)
 
Michalio said:
PHP is sometimes weird language where you can do something that should be impossible, like changing types whenever you want :)

C programmers pass around void* pointers for that same purpose! It just is not at all common to see a function which returns a void*
 
Back
Top