background preloader

PHP Language

Facebook Twitter

Magic Methods. If you use the Magical Method '__set()', be shure that the call of<?

Magic Methods

Php$myobject->test['myarray'] = 'data';? Magic constants. Mod_fcgid and timeouts. At work we use mod_fcgid to run php (libapache2-mod-fcgid from Debian to be exact).

mod_fcgid and timeouts

This makes php nice and fast, but more importantly, it runs each site's php pages as that site's user. However, if php scripts start running for a long time, we start seeing cryptic error messages in the browser ("Premature end of script headers: php4-fcgi" for example) and also as cryptic errors in Apache's error log. Mod_fcgid. Summary Any program assigned to the handler fcgid-script is processed using the FastCGI protocol; mod_fcgid starts a sufficient number instances of the program to handle concurrent requests, and these programs remain running to handle further incoming requests.

mod_fcgid

This is significantly faster than using the default mod_cgi or mod_cgid modules to launch the program upon each request. However, the programs invoked by mod_fcgid continue to consume resources, so the administrator must weigh the impact of invoking a particular program once per request against the resources required to leave a sufficient number of instances running continuously. The pool of fcgid-invoked programs is shared between all httpd workers. Configuration directives below let the administrator tune the number of instances of the program that will run concurrently. XDebug. Xdebug provides an interface for debugger clients that interact with running PHP scripts.

XDebug

This section explains how to set-up PHP and Xdebug to allow this, and introduces a few clients. Introduction Xdebug's (remote) debugger allows you to examine data structure, interactively walk through your and debug your code. There are two different protocols to communicate with the debugger: the old GDB-like command protocol (GDB) which is implemented in Xdebug 1.3 and 2; and the DBGp protocol which is implemented in Xdebug 2. Clients. Exceptions. Extending Exceptions PHP 5 has an exception model similar to that of other programming languages.

Exceptions

An exception can be thrown, and caught ("catched") within PHP. Code may be surrounded in a try block, to facilitate the catching of potential exceptions. Each try must have at least one corresponding catch block. PhpDocumentor. What makes good documentation?

phpDocumentor

This is unanswerable, but there are a few things to keep in mind Writing Great Documentation Consider the audience The first question any writer must ask is "Who is my audience? " This will answer many questions. Can't install PEAR on Windows 7, Structures/Graph error. Php - PEAR on Windows: How to change pear.ini location. PHP Manual. Operators. Scope Resolution Operator ( The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.

Scope Resolution Operator (

When referencing these items from outside the class definition, use the name of the class. As of PHP 5.3.0, it's possible to reference the class using a variable. The variable's value can not be a keyword (e.g. self, parent and static). Paamayim Nekudotayim would, at first, seem like a strange choice for naming a double-colon. However, while writing the Zend Engine 0.5 (which powers PHP 3), that's what the Zend team decided to call it. Example #1 :: from outside the class definition. Variable scope. The scope of a variable is the context within which it is defined.

Variable scope

For the most part all PHP variables only have a single scope. This single scope spans included and required files as well. For example: Here the variable will be available within the included script. However, within user-defined functions a local function scope is introduced. Types. Arrays. How to Clear an Array Completely? Array Functions. Strings. A string is series of characters, where a character is the same as a byte.

Strings

This means that PHP only supports a 256-character set, and hence does not offer native Unicode support. See details of the string type. Note: string can be as large as up to 2GB (2147483647 bytes maximum) Syntax ¶ A string literal can be specified in four different ways: Single quoted ¶ String Functions. If you want a function to return all text in a string up to the Nth occurrence of a substring, try the below function.

String Functions

Works in PHP >= 5. (Pommef provided another sample function for this purpose below, but I believe it is incorrect.) Type Comparison. Some function to write out your own comparisson table in tsv format. Classes and Objects. Unit Testing. PHPUnit. PHPUnit. It’s a familiar situation: you’ve been developing on an application for hours and you feel like you’ve been going round in circles.

You fix one bug and another pops up. Sometimes, it’s the same one you found 30 minutes ago, and sometimes it’s new, but you just know it’s related. For most developers, debugging means either clicking around on the site, or putting in a whole load of debugging statements to hunt the problem down. You’ve been there, right?