 php syntax syntax syntaxhighlighted php code php only parses code within its delimiters  anything outside its delimiters is sent directly to the output and is not parsed by php the most common delimiters are php and which are open and close delimiters respectively script language php and script delimiters are also available short tags or and are also commonly used but like aspstyle tags or and they are less portable as they can be disabled in the php configuration for this reason the use of short tags and aspstyle tags is discouraged  29  the purpose of these delimiters is to separate php code from nonphp code including html everything outside the delimiters is ignored by the parser and is passed through as output  30  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 doublequoted and heredoc strings allow the ability to embed the variable s value into the string  31  php treats newlines as whitespace in the manner of a freeform language  except when inside string quotes and statements are terminated by a semicolon  32  php has three types of comment syntax  serves as block comments and as well as are used for inline comments  33  to output text to the browser either the print function or the echo function is used both functions are nearly identical the major difference is that print is slower than echo because the former will return a status indicating if it was successful or not whereas the latter does not return a status and only returns the text for output  34  data types php stores whole numbers in a platformdependent range this range is typically that of 32bit signed integers  unsigned integers are converted to signed values in certain situations this behavior is different from other programming languages  35  integer variables can be assigned using decimal positive and negative  octal  and hexadecimal notations real numbers are also stored in a platformspecific range they can be specified using floating point notation or two forms of scientific notation   36  php has a native boolean type that is similar to the native boolean types in java and c   using the boolean type conversion rules nonzero values are interpreted as true and zero as false as in perl and c   36  the null data type represents a variable that has no value the only value in the null data type is null   36  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  36  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  36  php also supports strings  which can be used with single quotes double quotes or heredoc syntax   37  functions php has hundreds of base functions and thousands more from extensions functions are not firstclass functions and can only be referenced by their name  38  userdefined functions can be created at any time without being prototyped  38  functions can be defined inside code blocks permitting a runtime decision as to whether or not a function should be defined function calls must use parentheses with the exception of zero argument class constructor functions called with the php new operator where parentheses are optional php supports quasi anonymous functions through the createfunction function although they are not true anonymous functions because anonymous functions are nameless but functions can only be referenced by name or indirectly through a variable functionname in php  38  objects basic objectoriented programming functionality was added in php 3  3  object handling was completely rewritten for php 5 expanding the feature set and enhancing performance  39  in previous versions of php objects were handled like primitive types   39  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 final classes as well as abstract methods and final methods  it also introduced a standard way of declaring constructors and destructors  similar to that of other objectoriented languages such as c   and a standard exception handling model furthermore php 5 added interfaces and allowed for multiple interfaces to be implemented there are special interfaces that allow objects to interact with the runtime system objects implementing arrayaccess can be used with array syntax and objects implementing iterator or iteratoraggregate can be used with the foreach language construct there is no virtual table feature in the engine so static variables are bound with a name instead of a reference at compile time  40  if the developer creates a copy of an object 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 the object s properties if a clone method is defined then it will be responsible for setting the necessary properties in the created object for convenience the engine will supply a function that imports the properties of the source object so that the programmer can start with a byvalue replica of the source object and only override properties that need to be changed  41  resources php includes 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  42  php has traditionally used features such as  magicquotesgpc  and magicquotesruntime 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 and when the escaping used is not completely correct  43  to make code portable between servers which do and do not use magic quotes developers can preface their code with a script to reverse the effect of magic quotes when it is applied  44  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 unixlike operating systems  multibyte strings  unispan   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  45  as with many scripting languages php scripts are normally kept as humanreadable source code even on production web servers  46  while this allows flexibility releasing scripts in source form is undesirable for commercial software developers and can raise issues with security of web servers as an example if a hacker acquires control of a server database passwords may be quickly discovered and undesirable changes to scripts may be made that remain undiscovered indefinitely various encoding tools are available for php to offer code protection  citation needed  span 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 opportunities for span optimization  47   and an example of a code optimizer is the zend optimizer php extension  48  php accelerators can offer significant 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 span optimization to provide increased execution performance  citation needed   