In this Intel, I assume that you have more C programming experience than PHP experience. First we will see the overview about C then we get into the similarities and differences.
PHP is as an interpreted C that you can embed in Html documents. It is more or less like C, except with untyped variables, a whole lot of web-specific libraries build in and everything hooked up directly to your favorite web server. The syntax of statements and function definitions should be familiar, except that variables are always proceeded by $, and functions do not require separate prototypes.
Similarities between C and PHP
Syntax:
Broadly speaking, PHP syntax is the same as in C
1, Code is blank-insensitive
2, Statements are terminated with semicolons
3, Function calls have the same structure
4, Curly braces make statements into blocks as in C
5, PHP supports C and C++ style comments
Operators:
In PHP, assignment operators, Boolean operators, comparison operators and the basic arithmetic operators behaves same as in C.
Control structures:
The basic control structures behave as they do in C, including supporting break and continue.
Many function names
In PHP many pre-defined function names are seems to be identical to C functions and its task is more or less similar but function names are not case sensitive in PHP.
Differences between PHP and C:
Even though PHP has inherited many similarities from C, but it also inherit the functionality from other languages like Perl, shell script, etc.
Dollar sign:
In PHP all variables are denoted with a leading $ sign. Variables in PHP do not need to be declared in advance of assignment and they also have no intrinsic type.
Types:
PHP has only two numerical types; integer and double. It has no separate character type.
Type conversion:
In php, types are not checked at compile time, and type errors do not typically occur at runtime either. Instead, variables and values are automatically converted across types as needed.
Arrays:
In php, syntax of array is similar to C but its functionality entirely different. They are actually associative arrays or hashes and “index” can be either a number or a string. They do not need to be declared or allocated in advance.
No structure type:
In php, there is no struct, because array and object types together make it unnecessary. The elements of a PHP array need not be of a consistent type.
Objects:
PHP5 introduces a much fuller object model, although in approach and syntax it owes more to Java than to C++.
No pointers:
Even though PHP has no pointers but its typeless variables play a similar role. It support variable references. We can emulate function pointers to some extent, in that function names can be stored in variables and called by using the variable rather than a literal name.
No prototypes:
In php, functions do not need to be declared before their implementation is defined, as long as the function definition can be found somewhere in the current code file or included files.
Memory management:
Php engine is effectively a garbage-collected environment (reference-counted), and in small scripts there is no need to do any deallocation. If you need to free memory within a script’s execution, call unset () on the variable that refers to it, which will release the memory for collection.
Compilation and linking:
In php, there is no separate compilation step for PHP scripts—the development cycle is simply edit-reload. Errors and warnings show up in the browser output by default, although there is also an error-logging capability.
Permissiveness:
PHP is more forgiving than C, PHP does not warn you if you use a variable that has not yet been assigned. If you would rather be warned, you can set error-reporting level by evaluating error_reporting (E_ALL) early in your script, or set the error-reporting level to E_ALL permanently by editing the php.ini file.
I hope after reading this Intel, as a C programming you will be more curious to learn PHP. Of course it is easy and very fast to develop any application with PHP while compare to C.
|
Contributor's Note
I am writing this Intel with my experience, when i started to learn PHP with my past experience as C programmer. Your Comments are Invited.
|