PHP

Sa Wikipedije, slobodne enciklopedije

PHP ili Personal Home Page (ili Hypertext Preprocessor) je jedno od najboljih server-side open source rješenja. PHP je reflektivni programski jezik prvobitno dizajniran za pravljenje dinamičkih web stranica. [1] PHP se uglavnom koristi za izvršavanje skripti na serverskoj strani (server-side scripting), ali se može koristiti sa komandnog linijskog interfejsa ili preko samostalne grafičke aplikacije.

Server side scripting predstavlja vid izvršavanja web skripti na webu, a samo mu ime kaže da se izvršava na serveru (suprotno od JavaScript-a koji se izvršava na klijentskoj strani - browseru). PHP je alternativa komercijalnim programskim jezicima (Microsoft ASP/VBScript/JScript, Macromedia ColdFusion, Sun Microsystems JSP/JAVA) i nekomercijalnom CGI-u/PERL-u.

Sadržaj

[uredi] Historija

PHP je napisan kao skup CGI binarnih fajlova u C programskom jeziku od strane danskog/grenlandskog programera Rasmusa Lerdorfa 1994. godine, kako bi zamijenio mali skup Perl skripti koje je koristio za održavanje lične stranice. [2]

Lerdorf je inicijalno napravio PHP kako bi prikazao svoj rezime i kako bi prikupio određene podatke, poput onih o broju posjeta na svojoj stranici. Personal Home Page Tools se pojavio u javnosti 8. juna 1995. godine nakon što ga je Lerdorf kombinovao sa vlastitim Form Interpreter-om kako bi napravio PHP/FI (ovo izdanje se smatra drugom verzijom PHP-a).

Zeev Suraski i Andi Gutmans, dva izraelska razvijača sa Technion IIT-a, su nanovo napisali parser 1997. godine i stvorili bazu za PHP 3, promjenivši ime jezika u rekurzivni inicijalizam PHP: Hypertext Preprocessor. Razvojni tim je zvanično izdao PHP/FI 2 u novembru 1997. godine nakon mjeseci beta testiranja. Javno testiranje PHP 3 je otpočelo, a zvanično puštanje u upotrebu se desilo juna 1998. godine. Suraski i Gutmans su tada započeli novo prerađivanje PHP jezgre, proizvodeći Zend Engine 1999. godine.[3] Također su osnovali Zend Technologies u Ramat Gani (Izrael) koja se bavi upravljanjem razvoja PHP-a.

Maja 2000. godine je izdat PHP 4 sa Zend Engine 1.0. Najskoriji update isporučen od The PHP Group je za stariju seriju PHP 4 koja je do maja 2007. uključivala verzije do 4.4.7. PHP 4 će imati osigurano snabdijevanje sigurnosnim updateima do 31. decembra 2007.[4]

13. jula 2004, izdat je PHP 5 sa novom Zend Engine II. PHP 5 je uključio nove karakteristike poput:[5]

  • Unapređena podrška za objektno-orjentisano programiranje
  • PHP Data Objects nastavak, koji definiše lightweight konzistentni interfejs za pristup bazama podataka
  • Poboljšane performanse
  • Bolja podrška za MySQL
  • Ugrađena podrška za SQLite
  • Integrisana SOAP podrška
  • Podatkovni iteratori
  • Rad s greškama preko izuzetaka

Posljednja stabilna verzija PHP-a je 5.2.3. koja je izdata 1. juna 2007. godine.

[uredi] Upotreba

PHP se općenito izvršava na web serveru, uzimajući PHP kod kao ulaz, kreirajući web stranice kao izlaz; međutim može se također koristiti za pravljenje skripti sa komandne linije i aplikacije za korisnički interfejs na klijentskoj strani. PHP se može koristiti na većini web servera i na gotovo svakom operativnom sistemu i platformi bez ikakve novčane nadoknade. PHP Group također obezbjeđuje kompletan izvorni kod za korisnike koji grade, podešavaju ili nadograđuju kod za vlastitu upotrebu.

[uredi] Izvršavanje skripti na serverskoj strani

Originalno dizajniran za kreiranje dinamičkih web stranica, PHP se načelno fokusira na server-side scripting odnosno izvršavanje skripti na serverskoj strani. Izvršavanjem PHP parsera sa web serverom i web browserom, PHP model se može uporediti sa drugim server-side scripting jezicima kao što su Microsoftov ASP.NET sistem, JavaServer Pages (Sun Microsystems) i Ruby on Rails framework, pošto svi oni obezbjeđuju dinamički sadržaj klijentu sa web servera.

Kako bi se direktnije takmičio sa framework pristupom, Zend radi na Zend Frameworku - skupu PHP gradivnih blokova i najboljih praksi u nastajanju (počevši od juna 2006); drugi PHP frameworkci sa istim osnovama uključuju CakePHP, PRADO i Symfony.

LAMP arhitektura je postala popularna u web industriji kao način za plasiranje jeftinih, pouzdanih, skalabilnih i sigurnih web aplikacija. PHP se obično koristi kao P dio u ovoj kompoziciji zajedno sa Linuxom, Apache serverom i MySQL-om, iako se P može odnositi i na Python programski jezik ili Perl.

PHP se može koristiti sa velikim brojem relacionih sistema za upravljanje bazama podataka (RDBMS), izvršava se na svim najpopularnijim web serverima i dostupan je za mnoge različite operativne sisteme. Prilagodljivost znači da PHP ima široku instalacionu osnovu na Internetu; preko 19 miliona internetskih domena su udomljene na serverima sa instaliranim PHP-om. [6]

Primjeri, popularnih server-side PHP aplikacija uključuju: phpBB, WordPress i MediaWiki.

[uredi] Izvršavanje skripti na komandnoj liniji

PHP također obezbjeđuje komandni linijski interfejs SAPI za razvoj shell i desktop aplikacija, demona, log parsiranja i drugih sistemskih administrativnih zadataka. PHP se sve više koristi na komandnoj liniji za zadatke koji su tradicionalno pripadali Perlu, Pythonu, awk-u ili shell scriptingu.

[uredi] Aplikacije grafičkog interfejsa na klijentskoj strani

PHP obezbjeđuje povezivanje sa GUI bibliotekama poput GTK+ (sa PHP-GTK), Qt (sa PHP-Qt) i bibliotekama za tekstualni način rada poput ncurses radi olakšanja razvoja šireg opsega aplikacija grafičkog interfejsa za cross platforme.

Trenutno se vrše izmjene na ovom članku.
Kao znak dobre volje, suzdržite se od mijenjanja ovog članka dok je obavještenje prikazano kako bi izbjegli konflikte sa izmjenama.

[uredi] Sintaksa

PHP se primarno ponaša kao softverski filter. PHP program uzima informacije iz datoteke ili toka (stream) koji sadrže tekst i specijalne PHP instrukcije i izbacuje drugi tok podataka za prikazivanje. Od PHP 4, parser kompajlira ulaz za proizvodnju bytecode-a kojeg obrađuje Zend Engine, dajući poboljšanu performansu od interpreterskog prethodnika. Zend Engine II je u srcu PHP 5.

Školski primjer programa Hello World za PHP izgleda na sljedeći način:

<?php
echo 'Hello, World!';
?>

PHP samo parsira kod unutar svojih delimitera, kao što su <?php i ?>. Sve izvan toga se direktno šalje na izlaz i ne parsira se od strane PHP-a. Gornji primjer je ekvivalentan sljedećem tekstu na izlazu:

Hello, World!

Primarno korištenje ovoga je radi omogućavanja PHP iskazima da budu uklopljeni u HTML dokumente, naprimjer:

<?php
// PHP iskazi ovdje
?>
Regularni HTML ovdje 
<?php
// Više PHP iskaza
?>

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.

[uredi] 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.

[uredi] 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.

[uredi] Resources

[uredi] Libraries

Šablon:Main

PHP includes a large number of free and open source libraries with the core build. PHP is a fundamentally Internet-aware system with modules built in for accessing FTP servers, many database servers, embedded SQL libraries such as embedded MySQL and SQLite, LDAP servers, and others. Many functions familiar to C programmers such as those in the stdio family are available in the standard PHP build.

[uredi] Extension

PHP allows developers to write extensions in C to add functionality to the PHP language. These can then be compiled into PHP or loaded dynamically at runtime. Extensions have been written to add support for the Windows API, process management on Unix-like operating systems, multibyte strings (Unicode), cURL, and several popular compression formats. Some more unusual features include integration with Internet relay chat, dynamic generation of images and Adobe Flash content, and even speech synthesis. The PHP Extension Community Library (PECL) project is a repository for extensions to the PHP language.

[uredi] Source code encoders, optimizers and accelerators

As with many scripting languages, PHP scripts are normally kept as human-readable source code, even on production webservers. While this allows flexibility, it can raise issues with security and performance.

Encoders offer some source code security and enable proprietary software by hindering source code reverse engineering. Encoders fall broadly into two types; those that hide source code and those that compile code into optcode. The downside of this latter approach is that a special extension has to be installed on the server in order to run encoded scripts, however the approach of encoding compiled code and use of an extension offers typically the best performance, security and opportunity for additional features that may be useful for developers. Compiled code solutions may exploit the potential for increased security through the use of their own execution engine, although some simpler solutions rely on the regular PHP engine to execute the compiled code. The most commonly used packages for source code protection are from Zend Technologies and ionCube Ltd.

Code optimizers improve the quality of the compiled code by reducing its size and making changes that can reduce the execution time and improve performance. The nature of the PHP compiler is such that there are often many opportunities for code optimization.

Accelerators offer performance gains by caching the compiled form of a PHP script in shared memory to avoid the overhead of parsing and compiling the code every time the script runs. They may also perform code optimization to provide increased execution performance. Both commercial (e.g. Zend Platform) and open source accelerators (e.g. xcache, eAccelerator, APC) are available.

[uredi] Debuggers and profilers

Debuggers and profilers allow developers to analyze running PHP code for potential and noted software bugs and bottlenecks. Examples of such software for PHP include APD and Xdebug.

[uredi] Templating engines

Templating engines provide macros that allow PHP applications to uniformly identify common variables. One popular templating engine is Smarty. PHP itself makes a good templating engine.

[uredi] PEAR

The PHP Extension and Application Repository (PEAR) project aims to provide reusable libraries and components for PHP development. PEAR projects are usually written in PHP code using the Object-oriented programming paradigm.

[uredi] Support

PHP has a formal development manual that is maintained by the free software community. In addition, answers to many questions can often be found by doing a simple internet search. PHP users assist each other through various media such as chat, forums, newsgroups and PHP developer web sites. In turn, the PHP development team actively participates in such communities, garnering assistance from them in their own development effort (PHP itself) and providing assistance to them as well. There are many help resources[7] available for the novice PHP programmer.

[uredi] Criticism

Criticisms of PHP include those general criticisms ascribed to other scripting languages and dynamically typed languages. This list includes criticisms that have been rectified in recent versions.

  • PHP originally inserted data received over the network directly into the language namespace ("register_globals"), leading to confusion between trusted and untrusted data, and unnecessary potential for security holes in PHP applications. This behavior was turned off by default from version 4.2.0 released in April 2002.[8] However, this feature is still being used by some legacy applications[9].
  • PHP has traditionally used features such as "magic_quotes_gpc" and "magic_quotes_runtime" which attempt to escape apostrophes (') and quotes (") in strings in the assumption that they will be used in databases, to prevent SQL injection attacks. This leads to confusion over which data is escaped and which is not, and to problems when data is not in fact used as input to a database. [10]
  • PHP does not have complete native support for Unicode or multibyte strings. [11]
  • PHP does not enforce the declaration of variables prior to their use, and variables which have not been initialized can have operations (such as concatenation) performed on them; an operation on an uninitialized variable raises an E_NOTICE level error, but this is hidden by default.
  • PHP has no namespace support, which leads to a very large amount of globally available functions that can easily number into the thousands.
  • PHP's dynamic type conversion could potentially cause problems. Variable types in PHP, although they exist, are transparent to the programmer. Some may consider this a feature, as a variable can change from a number to a string and back again without extra lines of code. However, variable type errors are not detected at compile-time, and the dynamic-typing behavior lacks full predictability.
  • The standard function library lacks internal consistency. Many functions perform relatively similar actions and have different name standards and argument orders. For example:
    • Argument consistency: strpos($haystack, $needle) vs. in_array($needle, $haystack)
    • Naming convention: both of these work case-insensitively strcasecmp() vs. stristr() but the former indicates this with "case" while the later does with "i"
    • Function name consistency: strpos() vs. str_replace()
  • Functions are not first-class objects. This requires referencing functions by strings and object methods as a two-element array of the object and method name as a string. Consequently, anonymous functions are also referenced by string.
  • Lack of late static binding [12]
  • Some portability issues with 32-bit and 64-bit integers, and sometimes unsigned integers get converted to signed values.[13]

[uredi] Important release history

Version Release date Most important changes
PHP 1.0 June 8, 1995 Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP".
PHP Version 2 (PHP/FI) April 16, 1996 Considered by its creator as the "fastest and simplest tool" for creating dynamic web pages .
PHP 3.0 Jun 6, 1998 Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewrite the base for this version.
PHP 4.0 May 22, 2000 Added more advanced two-stage parse/execute tag-parsing system called the Zend engine.
PHP 4.1 Dec 10, 2001 Introduced the superglobals ($_GET, $_SESSION, etc.)
PHP 4.2 April 22, 2002 Disabled register_globals by default
PHP 4.3 Dec 27, 2002 Introduced the CLI, in addition to the CGI
PHP 4.4 July 11, 2005
PHP 5.0 July 13, 2004 Zend Engine II with a new object model.
PHP 5.1 Nov 25, 2005
PHP 5.2 Nov 2, 2006 Enabled the filter extension by default

[uredi] Future development

PHP 6, in development as of July 2007, aims to address some of PHP 5's shortcomings.[14]

  • Namespace support will be added
  • Native Unicode support will be added
  • The magic_quotes option will be removed
  • The HTTP_*_VARS global variables will be removed
  • The register_globals option will be removed
  • The safe_mode option will be removed

[uredi] See also

Portal
Ovaj članak je dio portala pod nazivom:
Free software
  • Associative array
  • Comparison of programming languages
  • Heredoc
  • List of PHP editors
  • List of web application frameworks
  • Paamayim Nekudotayim
  • Phalanger
  • PHP accelerator
  • Roadsend PHP
  • Standard PHP Library
  • Zend Framework

[uredi] Reference

[uredi] Further reading

  • Kerner, Sean Michael. "Is PHP The Cure For The 'Broken' Web?", internetnews.com, 13 September 2006. 
  • Kerner, Sean Michael. "Microsoft Opens PHP Door", internetnews.com, 31 October 2006. 
  • Sweat, Jason E (2005). Guide to PHP Design Patterns, PHP|architect.
  • Alshanetsky, Ilia (2005). Guide to PHP Security, PHP|architect.
  • Shiflett, Chris (2005). Essential PHP Security, O'Reilly Media.
  • Ullman, Larry (2003). PHP and MySQL for Dynamic Web Sites, 1st Edition, Peachpit Press.
  • Vaswani, Vikram (2007). PHP Programming Solutions, McGraw-Hill.

[uredi] External links

Šablon:Wikibooks Šablon:Wikiversity

[uredi] Vanjski linkovi