Make a comparative study about the two well-known high level languages today known as PHP and Python. Based your study on the guidelines shown below.
Case Study Content:
1. ABSTRACT
2. INTRODUCTION
3. Are PHP and Python are fundamentally different or fundamentally Alike?
4. Technical Details of the Two Programming Languages.
5. SUMMARY
6. CONCLUSION
7. RECOMMENDATION
Guidelines:
1. ABSTRACT
Today’s technology is fast evolving these days. Competition is high in terms of developing computer software. So, for me as a systems developer/systems developer instructor, I try to find software that meets my criteria in choosing a programming language to be use in creating the systems. A programming language is a set of English-like instructions that includes a set of rules for putting the instructions together to create commands. A translator changes the English-like commands into numeric code that the computer can understand. The most common type of translator is a compiler. The compiler is program that reads English-like commands in a file and than creates another file containing computer readable numeric code or commands. I have a lot of factors to consider in choosing a programming language but in this case study I will just compared two programming languages head-on, the PHP and PHYTON. The following chapters of my case study will show the advantages and disadvantages of each programming languages and I will based my recommendation on the results.
2. INTRODUCTION
Choosing the right programming language to be use in developing software
plays a vital role in accomplishing your project in a fast and convenient way.
The fact that there are a lot of available programming languages in the market,
so the question on how to choose the right programming languages is a valid
question. In this case study I will going to present some facts that will help
you choose you programming language between the PHP and Phyton only. I will not
going to convince you to use or tell you what is better, but rather decide it
by yourself. Though I will put some of my recommendations and comments in the
later part of this case study.
PHP is a server-side
scripting language designed for Web development but also used as a general-purpose
programming language. PHP is now installed on more than 20 million Web sites
and 1 million Web servers. Originally created by Rasmus Lerdorf in 1995, the reference
implementation of PHP is now produced by The PHP Group. While PHP originally
stood for Personal Home Page, it is now said to stand for PHP:
Hypertext Preprocessor, a recursive acronym.
PHP code is interpreted by a Web
server with a PHP processor module which generates the resulting Web page: PHP
commands can be embedded directly into an HTML source document rather than
calling an external file to process data. It has also evolved to include a command-line
interface capability and can be used in standalone graphical applications.
PHP is free software released under the PHP License,
which is incompatible with the GNU General Public License (GPL) due to
restrictions on the usage of the term PHP. PHP can be deployed on most
Web servers and also as a standalone shell on almost every operating system and
platform, free of charge and in the other hand Python is a general-purpose,
high-level programming language whose design philosophy emphasizes code readability.
Python's syntax allows for programmers to express concepts in fewer lines of
code than would be possible in languages such as C, and the language provides
constructs intended to enable clear programs on both a small and large scale.
Python supports multiple programming
paradigms, including object-oriented, imperative and functional programming
styles. It features a fully dynamic type system and automatic memory management,
similar to that of Scheme, Ruby, Perl and Tclm and has a large and
comprehensive standard library.
Like other dynamic languages,
Python is often used as a scripting language, but is also used in a wide range
of non-scripting contexts. Using third-party tools, Python code can be packaged
into standalone executable programs. Python interpreters are available for many
operating systems.
CPython, the reference
implementation of Python, is free and open source software and has a
community-based development model, as do nearly all of its alternative
implementations. CPython is managed by the non-profit Python Software
Foundation.
3. Are PHP and Python are fundamentally different or fundamentally Alike?
For me php and python are fundamentally different or fundamental alike because if a professional programmer can do php codes it also become easier in python. Php was design for web development to produce dynamic web pages while python was designed to emphasize productivity and code readability.
Both PHP and
Python:
·
are interpreted, high
level languages with dynamic typing
·
are supported by large
developer communities
·
are easy to learn
(compared to C++, Perl)
·
are easy to extend in
C, C++ and Java
·
are extremely
portable. They run on almost all platforms in existence without recompilation.
·
support for variable
number of function arguments.
·
have the ability to
freeze live objects in a string representation (for storing arbitrary objects
on disk, moving them over the network, etc); they can then be converted back to
identical objects with data intact. PHP's serialize function; Python's pickle
and marshal modules. Note that PHP, handling of serialized objects and classes
is much weaker and error prone than Python's due to PHP's lack of modules. When
an object is serialized, only its attributes are stored, not its methods. Thus,
the object's class must be present (with the exact same name) in the script
that unserializes it. In Python this is handled automatically via the
module/import framework. (this COULD be handled with PHP 5's autoload(), but is
not done automatically)
·
support namespaces
·
support for docstring
(pydoc / reflection + phpDocumenter)
·
support method
chaining
·
have several debuggers
and IDEs
·
support for dates that
aren't limited to UNIX timestamps (<1970>2038)1970>
·
support for cached
byte-code compilation (an extension in PHPs case)
·
have a standardized
database API
·
support GTK and QT
·
support lambdas and
other builtin functional programming constructs
·
have a single
statement (unset/del)
for all data types
·
can be used for
scripting and general programming (CLI sapi, embedded etc., in the case of PHP)
Compared as Languages
Functionalities of PHP
·
syntax from C/C++ and
Perl, with lots curly braces and dollar signs and "->"-s
·
the 'switch' statement
and 'do ... while' construct
·
increment and
decrement and assignment operators (assignment is a statement only in Python)
·
the ternary
operator/statement (... ? ... : ...)
o Retort: Python
2.5 has conditional expressions
·
confused tableau of
function names. The builtin library has a wide variety of naming conventions. Functions
often have prefixes to denote their source (but often not). Functions are often
placed into classes to simulate namespaces.
·
a somewhat weak type
system (not to be confused with dynamic types)
·
an expedient (commonly
installed) environment
·
one array type that
doubles as a list and a dictionary. Dictionary keys are iterated in their
original order.
·
private, protected and
public modifiers for both properties and methods
·
abstract and final
modifiers for both classes and methods
·
interfaces
o Note: However,
as Python has multiple inheritance, there's less need for interfaces. Also
Python 2.6 has introduced Abstract Base Classes.
·
variable variables
·
default arguments in
functions
·
embedding in HTML
o Note: mod_python
got this aswell.
·
a wide range of byte-code caches available
Five Reason why I will choose PHP.
1.
It’s everywhere! There is not a
web-hosting company today that does not offer PHP capability in their hosting
packages. This gives me the complete freedom to ‘move’ (should I choose) to any
hosting provider without fear that I have to redo my website all over again. Of
course the same can be said of other scripting technology, like Perl, ASP etc,
but PHP just about blankets all web hosting service providers.
2.
Lots of FREE applications! This is
perhaps one of the biggest pull to using PHP. There are lots (and I mean lots)
of great open-sourced applications available on the ‘Net for me to download and
use – absolutely FREE! Hotscripts is one of my favorite places to go to look
through what application is available for PHP. They currently host over 10,000
entries in their directory for PHP Scripts and Programs alone – some are paid
applications, but the large majority are freely available. That amount of
choice is just staggering.
3.
A large community. The number of free
applications is a testament to the large and active PHP community. Many times,
when I come across a problem with PHP, chances are, someone somewhere has
already found a fix. If not, there’s plenty of people to consult. To me, it’s
really just safety-in-numbers.
4.
MySQL database. All web applications
needs a place to store its data – and what better place to do that than on the
best open-source database platform, MySQL. Why? Because MySQL is an industrial
strength database for the price of FREE, and it’s everywhere too. Together PHP
and MySQL is a potent combination – almost every available PHP open source
application today uses MySQL as the database.
5.
Easy to use, yet powerful. I know, I
had formal programming training, so ‘easy to use’ is very subjective, but I am
still going to point out that comparing to other scripting languages, PHP is
relatively easy to pick up, and powerful enough that you can build almost any
kind of web application you can imagine (see point 2!)
Functionalities of PHYTON
·
indentation is used to mark out block structure
rather than curly braces
o Retort: PHP curly braces make it work with HTML more easy
·
modules
·
Rules that help
catching typos more; reading an undefined variable is an error, it's not
silently treated as if it was null.
o Retort: PHP will issue E_NOTICE. This will be shown in a
develop environment.
§ Counter-retort: It's still dangerous in production
environment. As of the development, it's extra hassle to configure, watch logs,
etc., when it could just stop, as you are supposed to eliminate these problems
anyway. That PHP still has the more easy-going approach is probably because
people have utilized undefined vars a lot in existing code base, so they
couldn't fix this.
·
a small core (language or runtime?)
o retort: it
is not entirely true (substance
needed)
·
very clear, concise,
and orthogonal syntax
·
keyword arguments
(i.e., parameters passed by name instead of by position) to functions and
methods, easy support for default arguments
o Retort: PHP
have default arguments
§ Counter-retort: Defaults
are much less useful without keyword arguments
·
true object
orientation and 'first class' classes and functions
o Retort: OO
has been completely revamped in PHP 5
§ Counter-retort: But
it's still painfully, obviously a hack
·
classes are used
extensively in the standard library
o Retort: PHP
5 has SPL which is fully class-based
·
multiple inheritance
·
object-oriented file
handling
·
excellent
introspection
o Retort: PHP
5 Reflection
§ Counter-retort: We
said excellent introspection
·
everything is a
reference! (references are painful in PHP)
o Retort: Not
in PHP 5
§ Counter-retort: note
that arrays are still passed around by value (unless you add an explicit &)
§ Retort: You won't accidentally modify it.
·
consistent case
sensitivity (PHP functions are case insensitive, but variables are case
sensitive)
·
a simple array slicing
syntax
·
iterators
o Retort: in
PHP 5
·
structured exception
handling
o Retort: in
PHP 5
§ Counter-retort: where
are PHP 5's equivalent of else and finally?
§ Counter-retort 2: unfortunately
most standard PHP functions don't use exceptions for reporting errors, which
makes structured exception handling much less useful
·
operator overloading
o Retort: In
PHP you can use runkit extension to emulate the same feature
§ Counter-retort: "In PHP you have to use runkit
extension to emulate the same feature"
·
SWIG integration
·
threading
o Retort: Python
have Global Interpreter Lock so it's not really parallel
·
"with ...
as" statement to deal with resources that need closing reliably and
concisely
·
an excellent profiler
o Retort: XDebug, a debugging and profiling extension, that
supports both PHP4 and PHP5 is extremely popular
o Retort: PHP
had SPL Types which is included in PHP5 as a standard library
·
differentiation
between arrays (lists) and associative arrays (dictionaries).
o Retort: PHP
array is more flexible. In case developer want a true array, just use FixedArray in PHP SPL
·
cached byte-code
compilation built in
·
support for all major
GUI frameworks
·
strong
internationalization and UNICODE support
o Retort: PHP 6 will include Unicode support. This feature is available in
PHP5.2 and PHP5.3 via intl extension which can be found at pecl.php.net
o Retort: PHP
have mbstring for Unicode
·
tends to lead to much
more scalable applications -- importing modules is safer than textually
including code as in PHP: global variables are not used to exchange
information.
So, I can say that PHP and Phyton are different to each other in a significant way!!!
4. Technical Details of the Two Programming Languages.
Data Types- A data type refers to the type of
data a variable can store. PHP has eight (8) different data types you can work
with. These are:
·
integer
numbers
·
floating
point numbers
·
strings
·
booleans
·
arrays
·
objects
·
resouces
·
null
PHP
is an loosely-typed language, so a variable does not need to be of a specific
type and can freely move between types as demanded by the code it is being used
in. But you still need to know your data types in order to be able to work with
the language.
Conditional Statements
If Statement
Syntax:-
if ( expression ) { // code to execute if the expression
evaluates to true }
PHP
Example:- The following code would display a is bigger than b if $a is bigger than $b:
if ($a > $b)
echo "a is bigger than b"; ?>
echo "a is bigger than b"; ?>
IF Else Statement
Syntax:-
if ( expression ) {
// code to execute if the expression evaluates to true
} else {
// code to execute in all other cases
}
// code to execute if the expression evaluates to true
} else {
// code to execute in all other cases
}
PHP Example:- The following code would display a is bigger than b if $a is bigger than $b, and a is NOT bigger than
b otherwise:
if ($a > $b) {
echo "a is bigger than b";
} else {
echo "a is NOT bigger than b";
}
?>
echo "a is bigger than b";
} else {
echo "a is NOT bigger than b";
}
?>
Switch Statement
The switch statement is similar to a series of IF statements on the same expression. In many
occasions, you may want to compare the same variable (or expression) with many different
values, and execute a different piece of code depending on which value it
equals to. This is exactly what the switch statement is for.
Tips:-
That
unlike some other languages, the continue statement applies to switch and acts
similar to break. If you
have a switch inside a loop and wish to continue to the next iteration of the
outer loop, use continue 2.
Syntax:-
switch ( expression )
{
case result1:
// execute this if expression results in result1
break;
case result2:
// execute this if expression results in result2
break;
default:
// execute this if no break statement
// has been encountered hitherto
}
case result1:
// execute this if expression results in result1
break;
case result2:
// execute this if expression results in result2
break;
default:
// execute this if no break statement
// has been encountered hitherto
}
PHP Example:-
switch ($i) {
case 0:
echo "i equals 0";
case 1:
echo "i equals 1";
case 2:
echo "i equals 2";
}
?>
case 0:
echo "i equals 0";
case 1:
echo "i equals 1";
case 2:
echo "i equals 2";
}
?>
Control Statements (if, while, for) Instead of curly braces like in C/C++, Python uses tabs to define the scope of the statements. In this way, we use tabs to nest statements within control structures like for loops, while loops, and if-then-else statements. For loops for lists list = [3, 4, 5] for i in list: print(i) Results: 3 4 5 For loops with a range # Range takes args: range(beginning index, exclusive end) for i in range(1,4): print(i)
Results: 1 2 3 If, Then, Else statements # Set up some dummy variables for our example a = 1.2 b = 2.1 if ( a < a/ (a+b) ): print(a) elif ( a == a/ (a+b) ): print(a,b) else: print(b) Results: 2.1 While loops # Begin the count at 0 count = 0 # Print the running count inside of a loop while (count < 4): print(count) # Increment count count = count+1 Results: 0 1 2 3
· THE LOOP AND ITS LIMITATIONS
PHP has Loops execute a block of code a specified number of times, or while a specified
condition is true.
Increment/decrement Operators
|
||
Example
|
Name
|
Effect
|
++$a
|
Pre-increment
|
Increments $a by one, then returns $a.
|
$a++
|
Post-increment
|
Returns $a, then increments $a by one.
|
--$a
|
Pre-decrement
|
Decrements $a by one, then returns $a.
|
$a--
|
Post-decrement
|
Returns $a, then decrements $a by one.
|
Increment/Decrement
Example
echo "
Postincrement
";$a = 5;
echo "Should be 5: " . $a++ . "
\n";
echo "Should be 6: " . $a . "
\n";
echo "
Preincrement
";$a = 5;
echo "Should be 6: " . ++$a . "
\n";
echo "Should be 6: " . $a . "
\n";
echo "
Postdecrement
";$a = 5;
echo "Should be 5: " . $a-- . "
\n";
echo "Should be 4: " . $a . "
\n";
echo "
Predecrement
";$a = 5;
echo "Should be 4: " . --$a . "
\n";
echo "Should be 4: " . $a . "
\n";
?>
PHP Arithmetic Operators
Operator
|
Name
|
Description
|
Example
|
Result
|
x + y
|
Addition
|
Sum of x and y
|
2 + 2
|
4
|
x - y
|
Subtraction
|
Difference of x
and y
|
5 - 2
|
3
|
x * y
|
Multiplication
|
Product of x and
y
|
5 * 2
|
10
|
x / y
|
Division
|
Quotient of x and
y
|
15 / 5
|
3
|
x % y
|
Modulus
|
Remainder of x
divided by y
|
5 % 2
10 % 8 10 % 2 |
1
2 0 |
- x
|
Negation
|
Opposite of x
|
- 2
|
|
a . b
|
Concatenation
|
Concatenate two
strings
|
"Hi" .
"Ha"
|
HiHa
|
Python Comments
Comments that contradict the code are worse than no comments. Always make a priority of keeping the comments up-to-date when the code changes!
Comments should be complete sentences. If a comment is a phrase or sentence, its first word should be capitalized, unless it is an identifier that begins with a lower case letter (never alter the case of identifiers!).
Block Comments
Block comments generally apply to some (or all) code that follows them, and are indented to the same level as that code. Each line of a block comment starts with a # and a single space (unless it is indented text inside the comment).
Paragraphs inside a block comment are separated by a line containing a single #.
Inline Comments
Use inline comments sparingly.
An inline comment is a comment on the same line as a statement. Inline comments should be separated by at least two spaces from the statement. They should start with a # and a single space.
Inline comments are unnecessary and in fact distracting if they state the obvious. Don't do this:
x = x + 1 # Increment x
But sometimes, this is useful:
x = x + 1 # Compensate for border
· ERROR Exception
Python
lass MessageError(Exception):
"""Base class for errors in the email package."""
Class naming conventions apply here, although you should add the suffix "Error" to your exception classes, if the exception is an error. Non-error exceptions need no special suffix.
When raising an exception, use raise ValueError('message') instead of the older form raise ValueError, 'message'.
The paren-using form is preferred because when the exception arguments are long or include string formatting, you don't need to use line continuation characters thanks to the containing parentheses. The older form is not legal syntax in Python 3.
When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause.
For example, use:
try:
import platform_specific_module
except ImportError:
platform_specific_module = None
PHP
Exception is the base class for all Exceptions.
· Functions
i. Non-value and Value Returning Functions
The real power of PHP comes from its functions.
In PHP, there are more than 700 built-in functions.
PHP Built-in Functions
For a complete reference and examples of the built-in functions, please visit our PHP Reference.
Create a PHP Function
A function will be executed by a call to the function.
Syntax
function functionName()
{
code to be executed;
}
PHP function guidelines:
Give the function a name that reflects what the function does
The function name can start with a letter or underscore (not a number)
Example
A simple function that writes my name when it is called:
function writeName()
{
echo "Kai Jim Refsnes";
}
echo "My name is ";
writeName();
?>
Output:
My name is Kai Jim Refsnes
A function is a block of organized, reusable code that is used to perform a single, related action. Functions provides better modularity for your application and a high degree of code reusing.
As you already know, Python gives you many built-in functions like print() etc. but you can also create your own functions. These functions are called user-defined functions.
Defining a Function
You can define functions to provide the required functionality. Here are simple rules to define a function in Python:
Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.
The first statement of a function can be an optional statement - the documentation string of the function or docstring.
The code block within every function starts with a colon (:) and is indented.
The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
Phyton Function Syntax:
def functionname( parameters ):
"function_docstring"
function_suite
return [expression]
By default, parameters have a positional behavior, and you need to inform them in the same order that they were defined.
Example:
Here is the simplest form of a Python function. This function takes a string as input parameter and prints it on standard screen.
def printme( str ):
"This prints a passed string into this function"
print str
return
· Records
MySQL databases - read a record with PHP. To read records from a database, the technique is usually to loop round and find the ones you want.
This is the updated translation of a beginner-level paper I wrote for Stacktrace one year ago (see http://stacktrace.it/articoli/2008/05/gestione-dei-record-python-1/). It basically discusses Python 2.6 namedtuples (plus some musing of mine).
· TYPE CHECKING
gettype — Get the type of a variable
*sigh*
No, typechecking arguments in python is not necessary. It is never necessary.
If your code accepts addresses as rawstring or as a Node object, your design is broken.
That comes from the fact that if you don't know already the type of an object in your own program, then you're doing something wrong already.
Typechecking hurts code reuse and reduces performance. Having a function that performs different things depending on the type of the object passed is bug-prone and has a behavior harder to understand and maintain.
You have the following saner options:
1) Make a Node object constructor that accepts rawstrings, or a function that converts strings in Node objects. Make your function assume the argument passed is a Node object. That way, if you need to pass a string to the function, you just do:
myfunction(Node(some_string))
That's your best option, it is clean, easy to understand and maintain. Anyone reading the code immediatelly understands what is happening, and you don't have to typecheck.
2) Make two functions, one that accepts Node objects and one that accepts rawstrings. You can make one call the other internally, in the most convenient way (myfunction_str can create a Node object and call myfunction_node, or the other way around).
3) Make Node objects have a __str__ method and inside your function, call str() on the received argument. That way you always get a string by coercion.
In any case, don't typecheck. It is completely unnecessary and has only downsides. Refactor your code instead in a way you don't need to typecheck. You only get benefits in doing so, both in short and long run.
· DATA ABSTRACTION
Data Abstraction Layer (DAL) in PHP, that will allow us to ignore the intricacies of MySQL and focus our attention on our Application Layer and Business Logic. Hopefully, by the end of this guide, you will have a working DAL and learn a little about PHP, MySQL, and Object-Oriented design in the process.
Object Parts:
Our Database class wills start off simple enough; we need only to define the class and our variables to get the ball rolling:
class Database
{
var $database_name;
var $database_user;
var $database_pass;
var $database_host;
var $database_link;
Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von Neumann’s model of a “stored program computer,” code is also represented by objects.)
Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether — it is a matter of implementation quality how garbage collection is implemented, as long as no objects are collected that are still reachable.
· Inheritance/Object Inheritance
Inheritance is a well-established programming principle, and PHP makes use of this principle in its object model. This principle will affect the way many classes and objects relate to one another.
For example, when you extend a class, the subclass inherits all of the public and protected methods from the parent class. Unless a class overrides those methods, they will retain their original functionality.
This is useful for defining and abstracting functionality, and permits the implementation of additional functionality in similar objects without the need to reimplement all of the shared functionality.
Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax and semantics. It is a mixture of the class mechanisms found in C++ and Modula-3. Python classes provide all the standard features of Object Oriented Programming: the class inheritance mechanism allows multiple base classes, a derived class can override any methods of its base class or classes, and a method can call the method of a base class with the same name. Objects can contain arbitrary amounts and kinds of data. As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation.
· GUI Tools
Python has a huge number of GUI frameworks
(or toolkits) available for it, from Tkinter (traditionally bundled with
Python, using Tk) to a number of other cross-platform solutions, as well as
bindings to platform-specific (also known as "native") technologies.
GUI Programming in Python is a similar page whose
content could arguably complement this page with some editing.
Cross-Browser Frameworks
Package
|
Target
|
Notes
|
All major Web Browsers
|
Comprehensive Widget toolkit, Python-to-Javascript compiler and AJAX library. Provides
the "V" in MVC. See alsoPyjamasDesktop
|
MongoDB GUI administration tool for PHP. Built on a stripped-down version of the Vork PHP framework.
· GLOBAL and Local VARIABLES
PHP Variables
As with algebra, PHP variables can be used to hold values (x=5) or expressions (z=x+y).
Variable can have short names (like x and y) or more descriptive names (age, carname, totalvolume).
Rules for PHP variables:
A variable starts with the $ sign, followed by the name of the variable
A variable name must begin with a letter or the underscore character
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
A variable name should not contain spaces
Variable names are case sensitive ($y and $Y are two different variables)
Creating (Declaring) PHP Variables
PHP has no command for declaring a variable.
A variable is created the moment you first assign a value to it:
$txt="Hello world!";
$x=5;
Community Support
PHP
·
huge installed user base, but the figures are probably distorted by
shared hosting
·
low signal-to-noise ratio -- because PHP is so expedient, many of the
users are not invested in the technology (or even their own code) or the
community
Python
·
sizable, but not huge, installed user base
·
Python Software Foundation
·
lots of specialized interest groups
·
very high signal-to-noise ratio
5. SUMMARY
Both PHP and Python:
- are interpreted, high level languages with dynamic typing
- are supported by large developer communities
- are easy to learn (compared to C++, Perl)
- are easy to extend in C, C++ and Java
- are extremely portable. They run on almost all platforms in existence without recompilation.
- support for variable number of function arguments.
- have the ability to freeze live objects in a string representation (for storing arbitrary objects on disk, moving them over the network, etc); they can then be converted back to identical objects with data intact. PHP's serialize function; Python's pickle and marshal modules. Note that PHP, handling of serialized objects and classes is much weaker and error prone than Python's due to PHP's lack of modules. When an object is serialized, only its attributes are stored, not its methods. Thus, the object's class must be present (with the exact same name) in the script that unserializes it. In Python this is handled automatically via the module/import framework. (this COULD be handled with PHP 5's autoload(), but is not done automatically)
- support namespaces
- support for docstring (pydoc / reflection + phpDocumenter)
- support method chaining
- have several debuggers and IDEs
·
support for dates that
aren't limited to UNIX timestamps (<1970>2038)1970>
- support for cached byte-code compilation (an extension in PHPs case)
- have a standardized database API
- support GTK and QT
- support lambdas and other builtin functional programming constructs
- have a single statement (unset/del) for all data types
- can be used for scripting and general programming (CLI sapi, embedded etc., in the case of PHP)
Compared as Languages
What does PHP have that Python doesn't?
·
syntax from C/C++ and
Perl, with lots curly braces and dollar signs and "->"-s
- the 'switch' statement and 'do ... while' construct
- increment and decrement and assignment operators (assignment is a statement only in Python)
- the ternary operator/statement (... ? ... : ...)
o Retort: Python
2.5 has conditional expressions
- confused tableau of function names. The builtin library has a wide variety of naming conventions. Functions often have prefixes to denote their source (but often not). Functions are often placed into classes to simulate namespaces.
- a somewhat weak type system (not to be confused with dynamic types)
- an expedient (commonly installed) environment
- one array type that doubles as a list and a dictionary. Dictionary keys are iterated in their original order.
- private, protected and public modifiers for both properties and methods
- abstract and final modifiers for both classes and methods
- interfaces
o Note: However,
as Python has multiple inheritance, there's less need for interfaces. Also
Python 2.6 has introduced Abstract Base Classes.
- variable variables
- default arguments in functions
- embedding in HTML
o Note: mod_python
got this aswell.
- a wide range of byte-code caches available
6. CONCLUSION
Based on the facts above, I can tell that I rather choose to use PHP over Phyton. Though it is my personal preference to use PHP because the syntax is more familiar to me because I’m a java developer also and also the great support in using or learning PHP is so great.
Although both PHP and Python have excellent core documentation, Python's is more extensive and generally higher quality. PHP has a large number of translations available. Python doesn't. For PHP and for Python Python allows documentation on modules, classes, and functions to be included in the program code. The documentation becomes an attribute of the module/class/function, accessible from inside of the language itself. Python manual is really awfully structurized and presented compared to PHP manual, which uses cross-links, a lot of colorized examples and invaluable user comments to make it easier to comprehend the magic. PHP manual merges different versions of the language together making it a little bit bloated.
7. RECOMMENDATION
Personally I will recommend the PHP, its not that I
know to much about PHP but maybe I’m not just so familiar with Phyton. Based on
my experience in developing using PHP I can simply find the solution everytime
I encounter a problem. So, its makes me think that I can do anything with PHP.
So with these, I’m more favor in PHP over Phyton.
8. REFERENCES
http://wiki.python.org/moin/PythonVsPhp
https://www.udemy.com/blog/modern-language-wars/
http://www.adager.com/VeSoft/ProgrammingLanguages.html
http://en.wikipedia.org/wiki/PHP
http://www.python.org/
http://dev.hubspot.com/blog/bid/85467/Evolution-of-a-Web-Developer-From-PHP-Newbie-To-Python-Ninja