PHP for Programmer C

The easiest way to think of PHP is as C is interpreted that you can embed in HTML documents. PHP is quite similar to C, except for untyped variables, Web-specific libraries are available, and everything is hooked up directly to your favorite Web Server.

The simplest way to think of PHP is like C is interpreted to be able to embed HTML documents. PHP is quite similar to C, except for untyped variables, Web-specific libraries are available, and everything is hooked up directly to your favorite Web Server.

The syntax of functions and function definitions is quite similar, except that there must always be $ before the variable name and the function does not require a separate prototype.

Here are some similarities and differences between PHP and C:

The similarity between PHP and C

Syntax - In general, PHP syntax is the same as in C: Code is irrespective of space (blank), the command is ended with a semicolon, the function call has the same structure (my_function (expression1, expression2)) , and curly braces ({and}) create blocks. PHP supports C and C ++ comments (/ * * / as well as //), Perl and Shell-script types (#).

Operator - Assignment operators (=, + =, * =, .), operators, logical operators (&&, ||,!), Comparison operators (<,>, <=,> =, ==,! =), and the basic arithmetic operators (+, -, *, /,%) operate in PHP the way they do in C.

Control structure - Basic control structures (if, switch, while, for) operate as they do in C, including support for breaks and continue. One notable difference is that the switch in PHP can accept strings as identifiers.

Function Name - When you study Documentation about PHP, you will see many function names that seem to be identical to C functions.

The difference between PHP and C

Symbol $ - Must have $ set the variable name. Variables do not need to be declared before the assignment, and they do not have an intrinsic type.

Type - PHP only has two numeric types: Integer (corresponding to a long in C) and double (corresponding to a double in C). String (string) of arbitrary length. There are no individual character types.

Type conversion - Type not checked at compile time, and type errors do not appear at runtime. Instead, variables and values ​​are automatically converted when needed.

Array (Array) - Arrays with a syntax that are similar to the array C syntax, but how they are implemented are completely different. They are actually associative or hash arrays, and the index can be a number or a string. They do not need to be declared or allocated memory.

No structure type - There is no structure in PHP, partly because array and object types together make it unnecessary. Elements of an array in PHP are not a homogeneous type.

No pointers - There are no pointers available in PHP, although variables play a similar role. PHP does not support variable references. You can also simulate function pointers to several ranges, in which function names can be stored in variables and called using variables rather than a constant name.

There is no Prototype - Functions do not need to be declared before their implementer is defined, provided that the definition can be found somewhere in the currently included code or file.

Memory management - PHP effectively performs code cleanup, and with small scripts, there is no need to perform any memory release. You are free to allocate memory for new structures, for example, new strings and instances of objects. In PHP 5, it is possible for destructor definitions for objects. Destructor is called when the last reference to an object leaves the scope, before the memory is restored.

Compiler and link - There are no separate compilation steps for PHP scripts.

More arbitrary - PHP is more free than C (especially in its style system), and so you can avoid new types of errors. Unexpected results are more common than Error.

According to Tutorialspoint

Previous article: Object-oriented programming in PHP

Next lesson: PHP for PERL Programmers

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile