Monday, May 21, 2007

Tips for Learning Simple PHP

When you are trying to learn a new programming language like PHP, it can get a bit intimidating, especially if you have never had experience with other programming languages before. But trust me, the toughest hurdle is really the starting point. Once you have gotten over that, it is really just a matter of keeping your focus and practicing. Be patient and learn the steps one at a time and you will get there. Here are some tips to help you learn simple PHP:

Learn the basics.
To learn a new language, specifically a programming language, you will need to have basic computer skills. Before you can learn PHP, you need to have a basic background on HTML. This is necessary to make PHP easier to grasp. Plus, you can alternate between the two later on using the same document.

PHP is a language that uses scripting and often used with HTML to supplement functions that HTML lacks. With PHP, you can collect and process data, make comparisons and calculations things that you can not do with HTML. Using this skill, you can create other functions to produce data that is more specialized.

Get the tools.
To create PHP pages, you will need a text editor. A plain text editor is a program that lets you edit files in plain text. These are the ones that come with extensions such as. php, .cgi, .html, etc. These types of text editors will not save formatting on the file, only the plain text. If you have been using a text editing program for your HTML file, that will do. you will probably use either Notepad (for Windows) or Text Edit (for Mac).

Get an FTP.
A File Transfer Protocol or FTP is used to exchange files from your computer to a remote server. This is the one we use to connect on a LAN or to an Internet site.

Get busy.
Once you have the right tools, you will have to practice creating files using PHP. There are some very important stuff that you will need to learn, including basic mathematics and IF statements and using variables. you will have to go through these first before you can hope to build a reliable PHP file.

Once you know your way around these skills, you can then start learning about loops. Loops are just your basic true or false statements that will perform repetitive actions again and again until certain conditions are met. After mastering the loops, you can then learn how to write your very own functions. Once you have learned how to manipulate the codes to create your desired result, there is virtually no limit to what you can do.

Online resources for learning simple PHP
You can not possibly learn simple PHP from a single short article like this, so it is best to expand your knowledge and turn to other resources like books and online sites. Some sites to check out:

PHP.About.com
There are several articles on this site that discuss the most basic information you need to know to learn simple PHP. This is a great source for web based tutorial that features clear step by step instructions on using PHP, HTML, XML and MySQL databases.

PHP Buddy.com
This site contains Quick Start tutorials on PHP and scripts that will make it easy for you to learn the program easily. This includes a brief introduction and learning basic PHP syntax. There are also valuable tutorials on using cookies, data inscription and working with functions and sessions using PHP.

PHP Freaks.com
This is a site for people who want to learn both PHP and MySQL. The site has 90 tutorials on PHP, more than 400 PHP code examples and nearly 3,000 articles that discuss various information, tips and tricks to make learning simple PHP quick and easy.

Ronald Firquain is a writer, marketer, entrepreneur, webmaster and has 16 years of computer knowledge. You can download e-books for making money online, building a website, improve your golf game, playing guitar and much more. For more information go to: eBooks-Mall

Thursday, May 17, 2007


Zend Technologies Inc., creator of the open-source PHP Web application development language, has announced new software to make PHP ready for the enterprise.

The Cupertino, Calif., company this week announced Zend Platform 1.1, an integrated software platform that delivers reliability, scalability and interoperability to PHP applications, said Pamela Roussos, vice president at Zend.

"We're seeing enterprise-class users beginning to adopt PHP for their applications," Roussos said.

"We asked a lot of users what they wanted, and they said they needed more reliability, scalability and interoperability as a way to make PHP enterprise-grade," Roussos said. "So that's why we did with Zend Platform. At its heart it's a central place where aggregators can manage and control their PHP applications."

Zend Platform delivers what Zend calls PHP Intelligence: performance management, configuration control and interoperability with Java applications.

Roussos said PHP Intelligence enables users to pinpoint problems in PHP applications, such as run-time errors; performance, script and function problems; and database errors.

Meanwhile, the new Zend Platform is tightly integrated with the Zend Studio integrated development environment for PHP, Roussos said.

This integration enables developers to "find problems and fix them," she said. "So we're tying together the life-cycle management. We're tying in development with production."

Roussos said that although Zend is formally announcing Zend Platform this week, the company did a "quiet release into our installed base" in October and already has 150 customers for the platform.

Zend also on Monday announced a beta release of Zend Studio 4.0, which features integration with the Zend platform and enhanced database integration. Zend Studio 4.0 supports MySQL, SQLite, Oracle, Microsoft SQL Server, IBM DB2, Cloudscape and PostgreSQL, Roussos said.

Check out eWEEK.com's Web Services Center for the latest news, reviews and analysis in Web services.

Copyright © 2005 Ziff Davis Media Inc. All Rights Reserved. Originally appearing in eWEEK.

For me, coding in PHP has been a good news/bad news thing. The good news is that the language has a large development community, which brings to it a boat-load of tools and support sites. I also appreciate the existing applications and code base.

The bad news is that the actual writing of the code can get to be a chore. The PHP code-writing environments that I have used require a bit (sometimes a lot) of work to get up and running. Also, the "code assist" features in those tools are limited — not much more than auto-indentation and color coding to indicate keywords.

In short, none of the PHP IDEs that I have come across offer the power of the Visual Studio IDE to which I have become accustomed in my .NET coding activities. I always thought that it would be really cool if I could program in PHP under VS. Well, it seems that I can.

JCX Software promises that VS.PHP, its VS 2005 add-in, brings the power and versatility of the Visual Studio IDE to PHP coding. Among its advertised features are:

Intelli-Sense support for keyword selection, function selection, and code completion. Code outlining Support for PhpDoc within the Visual Studio IDE The ability to debug server side PHP code and client side Javascript code in the same session Runs under the PHP4 or PHP5 run-time engine Automatic deployment

With a list like that, I was interested. I took VS.PHP for a spin. First, I did some small demo work to see if the product did all it claimed. Then I ported an existing PHP project into VS.PHP — one that I was working on anyway — to really take the product to task. In this article, I'll tell you how it all worked out.

Working the IDE

VS.PHP really is about writing PHP code within the Visual Studio environment. Thus, everything that I knew how to use in VS.NET was readily available in VS.PHP. Adding new and existing items to a PHP project was no different than adding items to a C# or VB project. The class browser did a good job of showing me my classes, independent of file location. I could view a PHP class's methods and fields just as I would under a C# or VB project.

The code edit window is straight-ahead Visual Studio. If the file being edited has more than one class defined, you select the class from the top left drop-down. The right drop-down displays a list of the class's constructors and methods. The code window supports Intelli-Sense's display of a variable's options, and the standard PHP functions are listed when you strike Ctrl+Spacebar.

VS.PHP ships with a whole bunch of PHP libraries that you add to the Visual Studio PHP project as references. Once a reference is added, the libraries — such as one for MySQL support — are available for auto-select.

Also, VS.PHP supports code complete of object variables. But more about this later.

Runtime errors are reported using the PHP runtime engine. So, unlike a standard .NET project — where you get you a very detailed exception dump from the Common Language Runtime (CLR) — VS.PHP provides the standard PHP error dump into the Web page in which the error occurs. The PHP runtime reports the error's file and line location and a brief error message (best understood by experienced PHP developers).

Server Side Debugging

After the initial Hello World run, I put some break points in the PHP code. I had no problem examining a variable's value using QuickWatch and subsequently assigning a variable to a watch List.

VS.PHP provided a fully-functional Autos window. However, when I tried to go back into my code using the Visual Studio Set Next Statement from the cursor's context menu, I discovered that the feature seemed not to be supported. Thus, moving back in code was a problem.

Client Side Debugging

Just as I had done previously in the server side code, I set a breakpoint in client side Javascript that was in a JS file separate from the PHP code, and I added client side Javacript variables to a watch list. No problem.

I did run into a bit of a problem when I was trying to debug client side code that was inline in a PHP file. When I set a breakpoint in the Javascript portion of the PHP file, upon the break VS.PHP sent me off into the PHP code. It did not break exactly on the Javascript line.

Intelli-sense, PHPDoc Support, and Code Outlining

One thing that makes .NET coding such a breeze in Visual Studio is the abiltity to view a class's properties and methods with the aid of Intelli-Sense. As you type, the Visual Studio IDE automatically displays an object variable's properties and methods. VS.PHP adapts this capability to PHP coding, and it's just as compelling.

I defined some simple classes in a PHP file, then began writing code with them. VS.PHP identified the object variable that interested me by alphabetic sort in an inline drop-down, just as Visual Studio would if I were coding in C# or VB. Also, once I entered the PHP class delimiter characters ->, VS.PHP displayed all the fields and methods associated with the given class.

Object-Oriented PHP

Object-Oriented PHP

Peter Lavin

No Starch Press

555 DeHaro, #250, San Francisco CA 94107

1593270771 $29.95 www.nostarch.com

The latest version of PHP is covered here in a title which teaches how to create your own code classes, customize and improve them, employ PHP to autogenerate code documentation and much more. Any with a working knowledge of PHP who want to move behind the basics to take full advantage of the latest version must have Object-Oriented PHP: Concepts, Techniques And Code: it encourages sequential learning through chapters which provide basic building blocks of experience and real-world applications. A top pick.

Saturday, May 5, 2007

Syntax

PHP primarily acts as a filter. The PHP program takes input from a file or stream containing text and special PHP instructions and outputs another stream of data for display. From PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor. The Zend Engine II is at the heart of PHP 5.

The usual Hello World code example for PHP is:

echo 'Hello, World!';
?>

PHP only parses code within its delimiters, such as . Anything outside its delimiters is sent directly to the output and not parsed by PHP. The example above is equivalent to the following text (and indeed is converted into this form):

Hello, World!

The primary use of this is to allow PHP statements to be embedded within HTML documents, for example:

// PHP statements here
?>
Regular HTML here
// More PHP Statements
?>


Variables are prefixed with a dollar symbol and a type does not need to be specified in advance. Unlike function and class names, variable names are case sensitive. Both double-quoted ("") and heredoc strings allow the ability to embed the variable's value into the string.

PHP treats new lines as whitespace, in the manner of a free-form language (except when inside string quotes). Statements are terminated by a semicolon, except in a few special cases.

PHP has three types of comment syntax: /* */ which serves as block comments, and // as well as # which is used for inline comments.

Data types

PHP stores whole numbers in a platform-dependent range. This range is typically that of 32-bit signed integers. Integer variables can be assigned using decimal (positive and negative), octal and hexadecimal notations. Real numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two forms of scientific notation.

PHP has a native Boolean type, named "boolean", similar to the native Boolean types in Java and C++. Using the Boolean type conversion rules, non-zero values can be interpreted as true and zero as false, as in Perl.

The null data type represents a variable that has no value. The only value in the null data type is NULL.

Variables of the "resource" type represent references to resources from external sources. These are typically created by functions from a particular extension, and can only be processed by functions from the same extension. Examples include file, image and database resources.

Arrays support both numeric and string indices, and are heterogeneous. Arrays can contain elements of any type that PHP can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in hashes with both keys and values, and the two can be intermingled.

Objects

Basic Object-oriented programming functionality was added in PHP 3. Handling of objects was completely rewritten for PHP 5, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types. The drawback of this method was that the whole object was copied when a variable was assigned, or passed as a parameter to a method. In the new approach, objects are referenced by handle, and not by value. PHP 5 introduced private and protected member variables and methods, along with abstract classes and abstract methods. It also introduced a standard way of declaring constructors and destructors similar to that of other object-oriented languages, such as C++, and an exception handling model similar to that of other programming languages.

The static method and class variable features in Zend Engine 2 do not work the way some expect. There is no virtual table feature in the engine, so the static variables are bound with a name at compile time instead of with a reference.

If the developer asks to create a copy of an object by using the reserved word clone, the Zend engine will check if a __clone() method has been defined or not. If not, it will call a default __clone() which will copy all of the object's properties. If a __clone() method is defined, then it will be responsible to set the necessary properties in the created object. For convenience, the engine will supply a function that imports all of the properties from the source object, so that they can start with a by-value replica of the source object, and only override properties that need to be changed.

Classes in PHP 4 & 5 are defined using the class keyword, followed by the class name and its whether it is extending another class or not. After that the class members are contained in a set of curly braces. The following example demonstrates classes in PHP

Simple Class Definition

class ClassName //Defines class "ClassName"
{
function hello()
{
echo "Hello Word!";
}
}
?>

Extending Class Definition

You are able to extend a previously defined class using the extend keyword. If the parent class contains methods with the same name then they are replaced by the extender's (or child's) version. You can reference the parents version from within the extender class's using the parent:: scope reference.

class ClassNameExtended extends ClassName //Defines class "ClassNameExtended" which adds functionality to "ClassName"
{
function goodBye()
{
echo "GoodBye World!";
}
}
?>

Member function & variable types

PHP 5.0 added support for encapsulation within classes, and added the keywords public, protected and private for use in method signatures.

class ClassName //Defines class "ClassName"
{
public function hello() //[Public availability Creates a function available for use by any code (like standard function)
{
echo "Hello, World!";
}

private function goodBye() //[Private availability] This function is available only to the ClassName class
{
echo "GoodBye, World!";
}

protected function fooBar() //[Protected availability] This function is available only to the ClassName class and its extendors or parents
{
echo "Foo on you World!";
}

}
?>

The Constructor/Destructor Method

A class constructor is a method that gets called as soon as an object of that class is initialized. On the flip side, a destructor is a method that is called as the class is terminated. The constructor is generally used to set default property values or initial calculation results for a new object. The destructor is often used for cleaning up (eg. closing database connections). In PHP 4 the constructor is created by creating a method with the same name as the class. In PHP 5 the constructor is identified by using the __construct() method, and the destructor is identified using the __destruct() method. The example below shows a very basic but important use of a constructor. The __destruct method can also be called to terminate an instance of the class.


Using the __Construct/Destruct methods (PHP 5.0+ only)

class ClassName //Defines the class "ClassName"
{
public function __construct() //Define a function with the name "__construct"
{
echo "Class is Starting! ";
}

public function __destruct() //Define a function with the name "__destruct"
{
echo "Class is Ending! ";
}

public function hello()
{
echo "Hello function called! ";
}
}

$instance = new ClassName(); //Initiate an instance of the class. This calls the __construct function

$instance->hello(); // This will call the hello function and print the text

//When the script ends the class will automatically terminate and call the __destruct function.
?>

Using the older construct method

(PHP 4.0+ only)
Older versions (pre 5.0) of PHP also supported constructor methods that work in a similar method. The constructor is defined by creating a method with the same name as the parent class:

class ClassName //Defines the class "ClassName"
{
public function ClassName() //Define a function with the name "ClassName"
{
echo "Class is Starting! ";
}
}

$instance = new ClassName(); //Initiate an instance of the class. This is call the ClassName function
?>

History

PHP was written as a set of CGI binaries in the C programming language by the Danish/Greenlandic programmer Rasmus Lerdorf in 1994, to replace a small set of Perl scripts he had been using to maintain his personal homepage.[3] Lerdorf initially created PHP to display his résumé and to collect certain data, such as how much traffic his page was receiving. "Personal Home Page Tools" was publicly released on June 8, 1995 after Lerdorf combined it with his own Form Interpreter to create PHP/FI (this release is considered PHP version 2).[4][5]

Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion - Israel Institute of Technology, rewrote the parser in 1997 and formed the base of PHP 3, changing the language's name to the recursive initialism "PHP: Hypertext Preprocessor". The development team officially released PHP/FI 2 in November 1997 after months of beta testing. Public testing of PHP 3 began and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP's core, producing the Zend Engine in 1999.[6] They also founded Zend Technologies in Ramat Gan, Israel, which actively manages the development of PHP.

In May 2000, PHP 4, powered by the Zend Engine 1.0, was released. The most recent update released by The PHP Group, is for the older PHP version 4 code branch which, as of May 2007, is up to version 4.4.7. PHP 4 is currently still supported by security updates for those applications that require it.

On July 13, 2004, PHP 5 was released powered by the new Zend Engine II. PHP 5 included new features such as:[7]

The latest stable version, PHP 5.2.2, was released on May 3, 2007.

Php

PHP (PHP:Hypertext Preprocessor) is a reflective programming language originally designed for producing dynamic web pages.[1] PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications. Textual User Interfaces can also be created using ncurses.

The main implementation is produced by "The PHP Group" and released under the PHP License. It is considered to be free software by the Free Software Foundation[2]. This implementation serves to define a de facto standard for PHP, as there is no formal specification.