Example listing
Example listing
Example listing
List of all the examples in the manual
- Example#0 –
An introductory example - Example#1 – Our first PHP script: hello.php
- Example#2 – Get system information from PHP
- Example#3 – Printing a variable (Array element)
- Example#4 – Example using control structures and
functions - Example#5 – Mixing both HTML and PHP modes
- Example#6
– A simple HTML form - Example#7
– Printing data from our form - Example#8 – Installation Instructions (Apache Shared
Module Version) for PHP - Example#9 – Installation Instructions (Static Module
Installation for Apache) for PHP - Example#10 – Example commands for restarting
Apache - Example#11 –
- Example#12 –
- Example#13 –
- Example#14 –
- Example#15 –
- Example#16 –
- Example#17 –
- Example#18 –
- Example#19 –
- Example#20 –
- Example#21 –
- Example#22 –
- Example#23 –
- Example#24 – Partial lighttpd.conf
- Example#25 – Spawning FastCGI Responders
- Example#26 – Connecting to remote php-fastcgi
instances - Example#27 –
- Example#28 –
- Example#29 – OpenBSD Package Install Example
- Example#30 – Debian Install Example with Apache 2
- Example#31 – Stopping and starting Apache once PHP is
installed - Example#32 – Methods for listing additional PHP 5
packages - Example#33 – Install PHP with MySQL, cURL
- Example#34 – Recommended OpCache configuration
- Example#35 – Recommended WinCache configuration
- Example#36 – Command line to configure IIS and PHP
- Example#37 – PHP 5 package structure
- Example#38 – CGI and FastCGI settings in php.ini
- Example#39 – Configuring FastCGI extension to handle PHP
requests - Example#40 – Configuring file access permissions
- Example#41 – Configuring FastCGI and PHP recycling
- Example#42 – Configuring FastCGI timeout settings
- Example#43 – Changing the location of php.ini file
- Example#44 – CGI and FastCGI settings in php.ini
- Example#45 – Creating IIS FastCGI process pool
- Example#46 – Creating handler mapping for PHP
requests - Example#47 – Determining the account used as IIS anonymous
identity - Example#48 – Configuring file access permissions
- Example#49 – Set index.php as a default document in
IIS - Example#50 – Configuring FastCGI and PHP recycling
- Example#51 – Configuring FastCGI timeout settings
- Example#52 – Changing the location of php.ini file
- Example#53 – PHP as an Apache 1.3.x module
- Example#54 – PHP and Apache 1.3.x as CGI
- Example#55 – PHP and Apache 2.x as handler
- Example#56 –
- Example#57 – PHP and Apache 2.x as CGI
- Example#58 – Configure Apache to run PHP as
FastCGI - Example#59 – ISAPI configuration of Sambar
- Example#60 – Enable Bzip2 extension for
PHP-Windows - Example#61 – Registry changes
- Example#62 – Passing environment variables and PHP settings
to a pool - Example#63 – set PHP settings in nginx.conf
- Example#64 – phpinfo call
- Example#65 – php.ini Environment Variables
- Example#66 – php.ini example
- Example#67 – Apache configuration example
- Example#68 – Advanced escaping using conditions
- Example#69 – PHP Opening and Closing Tags
- Example#70 – Integer literals
- Example#71 – Integer overflow on a 32-bit system
- Example#72 – Integer overflow on a 64-bit system
- Example#73 – Invalid example
- Example#74 – Valid example
- Example#75 – Heredoc string quoting example
- Example#76 – Heredoc in arguments example
- Example#77 – Using Heredoc to initialize static
values - Example#78 – Using double quotes in Heredoc
- Example#79 – Nowdoc string quoting example
- Example#80 – Nowdoc string quoting example with
variables - Example#81 – Static data example
- Example#82 – Simple syntax example
- Example#83 – Negative numeric indices
- Example#84 – Some string examples
- Example#85 – Differences between PHP 5.3 and PHP
5.4 - Example#86 – A simple array
- Example#87 – Type Casting and Overwriting example
- Example#88 – Mixed integer and string keys
- Example#89 – Indexed arrays without key
- Example#90 – Keys not on all elements
- Example#91 – Accessing array elements
- Example#92 – Array dereferencing
- Example#93 – Using array()
- Example#94 – Collection
- Example#95 – Changing element in the loop
- Example#96 – One-based index
- Example#97 – Filling an array
- Example#98 – Sorting an array
- Example#99 – Recursive and multi-dimensional
arrays - Example#100 – Iterable parameter type example
- Example#101 – Iterable parameter default value
example - Example#102 – Iterable return type example
- Example#103 – Iterable generator return type
example - Example#104 – Iterable type variance example
- Example#105 – Callback function examples
- Example#106 – Callback example using a Closure
- Example#107 – Default values of uninitialized
variables - Example#108 – Using global
- Example#109 – Using $GLOBALS instead of global
- Example#110 – Example demonstrating superglobals and
scope - Example#111 – Example demonstrating need for static
variables - Example#112 – Example use of static variables
- Example#113 – Static variables with recursive
functions - Example#114 – Declaring static variables
- Example#115 – Variable property example
- Example#116 – A simple HTML form
- Example#117 – Accessing data from a simple POST HTML
form - Example#118 – Old methods of accessing user input
- Example#119 – More complex form variables
- Example#120 – A setcookie example
- Example#121 – Valid and invalid constant names
- Example#122 – Defining Constants
- Example#123 – Defining Constants using the const
keyword - Example#124 – Associativity
- Example#125 – Undefined order of evaluation
- Example#126 – +, – and . have the same precedence
- Example#127 – Assigning by reference
- Example#128 – Bitwise AND, OR and XOR operations on
integers - Example#129 – Bitwise XOR operations on strings
- Example#130 – Bit shifting on integers
- Example#131 – Boolean/null comparison
- Example#132 – Transcription of standard array
comparison - Example#133 – Assigning a default value
- Example#134 – Non-obvious Ternary Behaviour
- Example#135 – Assigning a default value
- Example#136 – Nesting null coalescing operator
- Example#137 – Arithmetic Operations on Character
Variables - Example#138 – Logical operators illustrated
- Example#139 – Comparing arrays
- Example#140 – Using instanceof with classes
- Example#141 – Using instanceof with inherited
classes - Example#142 – Using instanceof to check if object is not an
instanceof a class - Example#143 – Using instanceof with interfaces
- Example#144 – Using instanceof with other
variables - Example#145 – Using instanceof to test other
variables - Example#146 – Avoiding classname lookups and fatal errors
with instanceof in PHP 5.0 - Example#147 – switch structure
- Example#148 – switch structure allows usage of
strings - Example#149 – Tick usage example
- Example#150 – Ticks usage example
- Example#151 – Declaring an encoding for the
script. - Example#152 – Basic include example
- Example#153 – Including within functions
- Example#154 – include through HTTP
- Example#155 – Comparing return value of include
- Example#156 – include and the return statement
- Example#157 – Using output buffering to include a PHP file
into a string - Example#158 – goto example
- Example#159 – goto loop example
- Example#160 – This will not work
- Example#161 – Pseudo code to demonstrate function
uses - Example#162 – Conditional functions
- Example#163 – Functions within functions
- Example#164 – Recursive functions
- Example#165 – Passing arrays to functions
- Example#166 – Passing function parameters by
reference - Example#167 – Use of default parameters in
functions - Example#168 – Using non-scalar types as default
values - Example#169 – Incorrect usage of default function
arguments - Example#170 – Correct usage of default function
arguments - Example#171 –
- Example#172 – Basic class type declaration
- Example#173 – Basic interface type declaration
- Example#174 – Typed pass-by-reference Parameters
- Example#175 – Nullable type declaration
- Example#176 – Strict typing
- Example#177 – Weak typing
- Example#178 – Catching TypeError
- Example#179 – Using … to access variable
arguments - Example#180 – Using … to provide arguments
- Example#181 – Type hinted variable arguments
- Example#182 – Accessing variable arguments in PHP 5.5 and
earlier - Example#183 – Use of return
- Example#184 – Returning an array to get multiple
values - Example#185 – Returning a reference from a
function - Example#186 – Basic return type declaration
- Example#187 – Strict mode in action
- Example#188 – Returning an object
- Example#189 – Nullable return type declaration (as of PHP
7.1.0) - Example#190 – Variable function example
- Example#191 – Variable method example
- Example#192 – Variable method example with static
properties - Example#193 – Complex callables
- Example#194 – Anonymous function example
- Example#195 – Anonymous function variable assignment
example - Example#196 – Inheriting variables from the parent
scope - Example#197 – Closures and scoping
- Example#198 – Automatic binding of $this
- Example#199 – Attempting to use $this inside a static
anonymous function - Example#200 – Attempting to bind an object to a static
anonymous function - Example#201 – Simple Class definition
- Example#202 – Some examples of the $this
pseudo-variable - Example#203 – Creating an instance
- Example#204 – Object Assignment
- Example#205 – Creating new objects
- Example#206 – Access member of newly created
object - Example#207 – Property access vs. method call
- Example#208 – Calling an anonymous function stored in a
property - Example#209 – Simple Class Inheritance
- Example#210 – Class name resolution
- Example#211 – property declarations
- Example#212 – Example of using a nowdoc to initialize a
property - Example#213 – Defining and using a constant
- Example#214 – Static data example
- Example#215 – Namespaced ::class example
- Example#216 – Constant expression example
- Example#217 – Class constant visibility modifiers
- Example#218 – Autoload example
- Example#219 – Autoload other example
- Example#220 – Autoloading with exception handling for
5.3.0+ - Example#221 – Autoloading with exception handling for
5.3.0+ – Missing custom exception - Example#222 – using new unified constructors
- Example#223 – Constructors in namespaced classes
- Example#224 – Destructor Example
- Example#225 – Property declaration
- Example#226 – Method Declaration
- Example#227 – Constant Declaration as of PHP 7.1.0
- Example#228 – Accessing private members of the same object
type - Example#229 – Inheritance Example
- Example#230 – :: from outside the class
definition - Example#231 – :: from inside the class
definition - Example#232 – Calling a parent’s method
- Example#233 – Static method example
- Example#234 – Static property example
- Example#235 – Abstract class example
- Example#236 – Abstract class example
- Example#237 – Interface example
- Example#238 – Extendable Interfaces
- Example#239 – Multiple interface inheritance
- Example#240 – Interfaces with constants
- Example#241 – Trait example
- Example#242 – Precedence Order Example
- Example#243 – Alternate Precedence Order
Example - Example#244 – Multiple Traits Usage
- Example#245 – Conflict Resolution
- Example#246 – Changing Method Visibility
- Example#247 – Traits Composed from Traits
- Example#248 – Express Requirements by Abstract
Methods - Example#249 – Static Variables
- Example#250 – Static Methods
- Example#251 – Defining Properties
- Example#252 – Conflict Resolution
- Example#253 – Overloading properties via the __get(),
__set(), __isset() and __unset() methods - Example#254 – Overloading methods via the __call() and
__callStatic() methods - Example#255 – Simple Object Iteration
- Example#256 – Object Iteration implementing
Iterator - Example#257 – Object Iteration implementing
IteratorAggregate - Example#258 – Sleep and wakeup
- Example#259 – Simple example
- Example#260 – Using __invoke()
- Example#261 – Using __set_state() (since PHP
5.1.0) - Example#262 – Using __debugInfo()
- Example#263 – Final methods example
- Example#264 – Final class example
- Example#265 – Cloning an object
- Example#266 – Access member of freshly cloned
object - Example#267 – Example of object comparison in PHP
5 - Example#268 – self:: usage
- Example#269 – static:: simple usage
- Example#270 – static:: usage in a non-static
context - Example#271 – Forwarding and non-forwarding
calls - Example#272 – References and Objects
- Example#273 – Namespace syntax example
- Example#274 – Declaring a single namespace
- Example#275 – Declaring a single namespace
- Example#276 – Declaring a single namespace with
hierarchy - Example#277 – Declaring multiple namespaces, simple
combination syntax - Example#278 – Declaring multiple namespaces, bracketed
syntax - Example#279 – Declaring multiple namespaces and
unnamespaced code - Example#280 – Declaring multiple namespaces and
unnamespaced code - Example#281 – Accessing global classes, functions and
constants from within a namespace - Example#282 – Dynamically accessing elements
- Example#283 – Dynamically accessing namespaced
elements - Example#284 – __NAMESPACE__ example, namespaced
code - Example#285 – __NAMESPACE__ example, global
code - Example#286 – using __NAMESPACE__ for dynamic name
construction - Example#287 – the namespace operator, inside a
namespace - Example#288 – the namespace operator, in global
code - Example#289 – importing/aliasing with the use
operator - Example#290 – importing/aliasing with the use operator,
multiple use statements combined - Example#291 – Importing and dynamic names
- Example#292 – Importing and fully qualified names
- Example#293 – Illegal importing rule
- Example#294 – Using global space specification
- Example#295 – Accessing global classes inside a
namespace - Example#296 – global functions/constants fallback inside a
namespace - Example#297 – Name resolutions illustrated
- Example#298 – Accessing global classes outside a
namespace - Example#299 – Accessing global classes outside a
namespace - Example#300 – Accessing internal classes in
namespaces - Example#301 – Accessing internal classes, functions or
constants in namespaces - Example#302 – Fully Qualified names
- Example#303 – Qualified names
- Example#304 – Unqualified class names
- Example#305 – Unqualified function or constant
names - Example#306 – Dangers of using namespaced names inside a
double-quoted string - Example#307 – Undefined constants
- Example#308 – Undefined constants
- Example#309 – The Built in Exception class
- Example#310 – Extending the Exception class (PHP
5.3.0+) - Example#311 – Throwing an Exception
- Example#312 – Exception handling with a finally
block - Example#313 – Nested Exception
- Example#314 – Multi catch exception handling
- Example#315 – Implementing range as a generator
- Example#316 – A simple example of yielding values
- Example#317 – Yielding a key/value pair
- Example#318 – Yielding NULLs
- Example#319 – Yielding values by reference
- Example#320 – yield from with iterator_to_array
- Example#321 – Basic use of yield from
- Example#322 – yield from and return values
- Example#323 – Using references with undefined
variables - Example#324 – Referencing global variables inside
functions - Example#325 – References and foreach statement
- Example#326 – $GLOBALS example
- Example#327 – $_SERVER example
- Example#328 – $_GET example
- Example#329 – $_POST example
- Example#330 – $_ENV example
- Example#331 – $_COOKIE example
- Example#332 – $php_errormsg example
- Example#333 – $http_response_header example
- Example#334 – $argc example
- Example#335 – $argv example
- Example#336 – Exception::getMessage example
- Example#337 – Exception::getPrevious example
- Example#338 – Exception::getCode example
- Example#339 – Exception::getFile example
- Example#340 – Exception::getLine example
- Example#341 – Exception::getTrace example
- Example#342 – Exception::getTraceAsString example
- Example#343 – Exception::__toString example
- Example#344 – Use set_error_handler to change error
messages into ErrorException. - Example#345 – ErrorException::getSeverity example
- Example#346 – Error::getMessage example
- Example#347 – Error::getPrevious example
- Example#348 – Error::getCode example
- Example#349 – Error::getFile example
- Example#350 – Error::getLine example
- Example#351 – Error::getTrace example
- Example#352 – Error::getTraceAsString example
- Example#353 – Error::__toString example
- Example#354 – Basic usage
- Example#355 – Basic usage
- Example#356 – Basic usage
- Example#357 – ArrayAccess::offsetExists example
- Example#358 – Basic usage
- Example#359 – Closure::bind example
- Example#360 – Closure::bindTo example
- Example#361 – Closure::call example
- Example#362 – Generator::getReturn example
- Example#363 – Generator::key example
- Example#364 – Using Generator::send to inject
values - Example#365 – Throwing an exception into a
generator - Example#366 – Basic WeakReference Usage
- Example#367 – Basic bindto usage example
- Example#368 – Fetch a page and send POST data
- Example#369 – Ignore redirects but fetch headers and
content - Example#370 – Fetch a page and send POST data
- Example#371 – Basic password usage example
- Example#372 – Detecting which URL we ended up on after
redirects - Example#373 – php://temp/maxmemory
- Example#374 – php://filter/resource=<stream to be
filtered> - Example#375 – php://filter/read=<filter list to apply to
read chain> - Example#376 – php://filter/write=<filter list to apply
to write chain> - Example#377 – php://memory and php://temp are not
reusable - Example#378 – Print data:// contents
- Example#379 – Fetch the media type
- Example#380 – Basic usage
- Example#381 – Opening a stream from an active
connection - Example#382 – This $session variable must be kept
available! - Example#383 – Traversing a RAR archive
- Example#384 – Opening an encrypted file (header
encryption) - Example#385 – Poor variable checking leads to….
- Example#386 – … A filesystem attack
- Example#387 – More secure file name checking
- Example#388 – More secure file name checking
- Example#389 – Script vulnerable to null bytes
- Example#390 – Correctly validating the input
- Example#391 – Hashing password field
- Example#392 – Hashing password using crypts
- Example#393 – Splitting the result set into pages …
and making superusers (PostgreSQL) - Example#394 – Listing out articles … and some
passwords (any database server) - Example#395 – From resetting a password … to
gaining more privileges (any database server) - Example#396 – Attacking the database hosts operating
system (MSSQL Server) - Example#397 – A more secure way to compose a query
for paging - Example#398 – Attacking Variables with a custom HTML
page - Example#399 – Exploiting common debugging
variables - Example#400 – Finding dangerous variables with
E_ALL - Example#401 – Example misuse with register_globals =
on - Example#402 – Example use of sessions with register_globals
on or off - Example#403 – Detecting simple variable poisoning
- Example#404 – Dangerous Variable Usage
- Example#405 – Disabling magic quotes server
side - Example#406 – Disabling magic quotes at
runtime - Example#407 – Hiding PHP as another language
- Example#408 – Using unknown types for PHP
extensions - Example#409 – Using HTML types for PHP extensions
- Example#410 – Basic HTTP Authentication example
- Example#411 – Digest HTTP Authentication example
- Example#412 – HTTP Authentication example forcing a new
name/password - Example#413 – A simple XForms search form
- Example#414 – Using an XForm to populate $_POST
- Example#415 – File Upload Form
- Example#416 – Validating file uploads
- Example#417 – Uploading array of files
- Example#418 – Uploading multiple files
- Example#419 – Saving HTTP PUT files
- Example#420 – Getting the title of a remote page
- Example#421 – Storing data on a remote server
- Example#422 – Example showing the difference to the
CGI SAPI: - Example#423 –
- Example#424 – Printing built in (and loaded) PHP and Zend
modules - Example#425 – Getting a syntax error when using double
quotes - Example#426 – Using single quotes to prevent the shell’s
variable substitution - Example#427 – Using the -B, -R and -E options to count the
number of lines of a project. - Example#428 – Using -v to get the SAPI name and the version
of PHP and Zend - Example#429 – –ini example
- Example#430 – basic –rf usage
- Example#431 – –rc example
- Example#432 – –re example
- Example#433 – –ri example
- Example#434 – Execute PHP script as shell script
- Example#435 – Script intended to be run from command line
(script.php) - Example#436 – Batch file to run a command line PHP script
(script.bat) - Example#437 – Executing code using the interactive
shell - Example#438 – Tab completion
- Example#439 – Setting php.ini settings in the
interactive shell - Example#440 – Starting the web server
- Example#441 – Starting with a specific document root
directory - Example#442 – Using a Router Script
- Example#443 – Checking for CLI Web Server
Use - Example#444 – Handling Unsupported File
Types - Example#445 – Accessing the CLI Web Server From
Remote Machines - Example#446 – Creating a new zval container
- Example#447 – Displaying zval information
- Example#448 – Increasing refcount of a zval
- Example#449 – Decreasing zval refcount
- Example#450 – Creating a array zval
- Example#451 – Adding already existing element to an
array - Example#452 – Removing an element from an
array - Example#453 – Adding the array itself as an element
of it self - Example#454 – Unsetting $a
- Example#455 – Memory usage example
- Example#456 – GC performance influences
- Example#457 – Running the above script
- Example#458 – Recompiling PHP to enable GC
benchmarking - Example#459 – GC statistics
- Example#460 – all_probes.d for tracing all PHP Static
Probes with DTrace - Example#461 – all_probes.stp for tracing all PHP Static
Probes with SystemTap - Example#462 – An apc.rfc1867 example
- Example#463 – A apc_add example
- Example#464 – apc_bin_load example
- Example#465 – A apc_cache_info example
- Example#466 – apc_cas example
- Example#467 – apc_dec example
- Example#468 – apc_define_constants example
- Example#469 – apc_delete_file example
- Example#470 – A apc_delete example
- Example#471 – apc_exists example
- Example#472 – A apc_fetch example
- Example#473 – apc_inc example
- Example#474 – apc_load_constants example
- Example#475 – A apc_sma_info example
- Example#476 – A apc_store example
- Example#477 – A APCIterator::__construct example
- Example#478 – A apcu_add example
- Example#479 – A apcu_cache_info example
- Example#480 – apcu_cas example
- Example#481 – apcu_dec example
- Example#482 – A apcu_delete example
- Example#483 – An apcu_entry example
- Example#484 – apcu_exists example
- Example#485 – A apcu_fetch example
- Example#486 – apcu_inc example
- Example#487 – A apcu_sma_info example
- Example#488 – A apcu_store example
- Example#489 – A APCUIterator::__construct example
- Example#490 – Typical session using tcplisten
- Example#491 – apd_callstack example
- Example#492 – apd_clunk example
- Example#493 – apd_continue example
- Example#494 – apd_croak example
- Example#495 – apd_dump_function_table
example - Example#496 – apd_dump_persistent_resources
example - Example#497 – apd_dump_regular_resources
example - Example#498 – apd_echo example
- Example#499 – apd_get_active_symbols example
- Example#500 – apd_set_pprof_trace example
- Example#501 – apd_set_session_trace_socket example
- Example#502 – apd_set_session_trace example
- Example#503 – apd_set_session example
- Example#504 – override_function example
- Example#505 – rename_function example
- Example#506 – bcompiler_load_exe example
- Example#507 – bcompiler_load example
- Example#508 – bcompiler_parse_class example
- Example#509 – bcompiler_read example
- Example#510 – bcompiler_write_class example
- Example#511 – bcompiler_write_constant
example - Example#512 – bcompiler_write_exe_footer
example - Example#513 – bcompiler_write_file example
- Example#514 – bcompiler_write_footer example
- Example#515 – bcompiler_write_