Qondio
Front
Intel
IntelMart
Shares
My Qondio
Account
Ashokrajan > Intel > PHP in a Perspective of C programmer

qondio.com/r4lI PRINT EMAIL

PHP in a Perspective of C programmer

By Ashokrajan Balakrishnan of Metis Technologies Private Limited

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.

Contributed by Ashokrajan on November 3, 2010, at 5:33 PM UTC.

PLEASE VISIT THE CONTRIBUTOR'S WEBSITE
Metis Technologies Private Limited
Web design,web development and SEO company
www.metistechnologies.in

Reactions

No reactions yet.

Rate This Intel

Please login or sign up to rate this intel.

Comments

Please login or sign up to add a comment.

I am so far behind in the learning curve, Ashokrajan. I think that your detailed intels are loaded with very valuable information.
Keep up the good work.
Best wishes.
Frederick

frederick Nov 4, 2010 14:50

CONTRIBUTOR'S REPLY

Thanks a lot for your encouragement
I will keep contributing my best

Share

Copyright Notice

The copyright for this content entitled "PHP in a Perspective of C programmer" has been specified by the contributor as:

Creative Commons Attribution-Share Alike 3.0 Details

This content may be copied, distributed, and modified, as long as a) the original author is acknowledged with a link back to the content page, and b) if the work is modified, the result is distributed with this same license. If you use this content according to the license specified, you must link to the following URL:

http://ashokb23.qondio.com/

Login Here with
Any Email Address
Any Password
No account? Sign up.

Intel Contributor
This intel was contributed by Ashokrajan


Ashokrajan

Qondio Archive
May, 2012
123456
78910111213
14151617181920
21222324252627
28293031


2008
January, February, March, April, May, June, July, August, September, October, November, December
2009
January, February, March, April, May, June, July, August, September, October, November, December
2010
January, February, March, April, May, June, July, August, September, October, November, December
2011
January, February, March, April, May, June, July, August, September, October, November, December
2012
January, February, March, April, May

Sign Up
Not a member yet? Qondio is a powerful network for making it online. If you have a website to promote, we can help. Sign up and get in on the action.

About Qondio
Welcome to Qondio! Discover the awesome power this network can deliver by going to our About page. Or you could skip straight to the Sign Up form.

ABOUT
SUCCESS GUIDE
FEATURES
FAQ
ADVERTISE
CONTACT
USAGE POLICY
PRIVACY POLICY


TWITTER
FACEBOOK