• Way of ordering data by associating values to keys
• Unique keys are associated with a single value, or set of values
• Arrays can be nested, so that a value in one array actually represents a complete other array (multi-dimensional arrays)

Creating Arrays


o EX: $x = array(‘a’, ‘b’, ‘c’);
o EX: $x = [‘a’, ‘b’, ‘c’];
o EX: $x = array(0 => ‘a’, 1 => ‘b’, 2 => ‘c’);
o EX: $x = [0 => ‘a’, 1 => ‘b’, 2 => ‘c’];


$x = array(
‘XML’ => ‘eXtensible Markup Language’
$x = [
‘XML’ => ‘eXtensible Markup Language’

Filling Arrays



o EX: $x = range(1.2, 4.1) // == array(1.2, 2.2, 3.2)


Web Services

A web service is a software system designed for interoperable interaction over a network.

A web service is defined with a WSDL (Web Services Description Language) document, and other systems interact with the web service using SOAP messages, transferred using HTTP with an XML serialization.

A web service is an abstract resource that provides a set of functions and is implemented by an agent, which sends and receives messages.

A provider entity provides the functionality of a web service with a provider agent and a requester entity uses the web service functionality with a requester agent.

Web services implement various technologies, some of which are XML, SOAP, and WSDL. XML is a standard format for data exchange.

Web service requests and responses are sent as XML messages.

The elements and attributes that may be specified in an XML document are specified in an XML Schema.

SOAP provides a standard framework for packaging and exchanging XML messages. WSDL is an XML document in the namespace for describing a web service as a set of endpoints operating on messages. A WSDL document specifies the operations (methods) provided by a web service and the format of the XML messages.

Installing the PHP Web Services Extensions

The SOAP and XML-RPC extensions are packaged with the PHP 5 installation. The SOAP extension and the XML-RPC extension are not enabled by default in a PHP installation. To enable the SOAP and XML-RPC extensions add the following extension directives in the php.ini configuration file.



REST Context Switching

o Refers to the act of providing different output based on criteria from the request

o The process inspects the http request headers and/or the request uri, and varies the response appropriately

o Commonly used for:

 providing different output for requests originated via xmlhttprequest

 providing different output based on accept http headers (ex: rest endpoints)

 providing alternate layouts/content based on browser detection



REST stands for “REpresentational State Transfer”. It is a concept or architecture for managing information over the internet. REST concepts are referred to as resources. A representation of a resource must be stateless. It is usually represented by JSON.

API stands for “Application Programming Interface”. It is a set or rules that allows one piece of software application to talk to another. Those “rules” can include create, read, update and delete operations.

Client-Server: This constraint operates on the concept that the client and the server should be separate from each other and allowed to evolve individually.

Stateless: REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully.

Cache: Because a stateless API can increase request overhead by handling large loads of incoming and outbound calls, a REST API should be designed to encourage the storage of cacheable data.

Uniform Interface: The key to the decoupling client from server is having a uniform interface that allows independent evolution of the application without having the application’s services, or models and actions, tightly coupled to the API layer itself.

Layered System: REST APIs have different layers of their architecture working together to build a hierarchy that helps create a more scalable and modular application.

Code on Demand: Code on Demand allows for code or applets to be transmitted via the API for use within the application.

Unlike SOAP, REST is not constrained to XML, but instead can return XML, JSON, YAML or any other format depending on what the client requests. And unlike RPC, users aren’t required to know procedure names or specific parameters in a specific order.

One of the disadvantages of RESTful APIs is that you can lose the ability to maintain state in REST, such as within sessions. It can also be more difficult for newer developers to use.



This function is useful to check if the SOAP call failed, but without using exceptions. To use it, create a SoapClient object with the exceptions option set to zero or FALSE. In this case, the SOAP method will return a special SoapFault object which encapsulates the fault details (faultcode, faultstring, faultactor and faultdetails).

If exceptions is not set then SOAP call will throw an exception on error. is_soap_fault() checks if the given parameter is a SoapFault object.



This function sets whether or not to use the SOAP error handler in the SOAP server. It will return the previous value. If set to TRUE, details of errors in a SoapServer application will be sent to the client as a SOAP fault message. If FALSE, the standard PHP error handler is used. The default is to send error to the client as SOAP fault message.


XML Character Encoding

Source Encoding

• Conducted at time of parsing
• Cannot be changed during parser lifetime
• Types

  1. UTF-8 (php uses this type for internal document representation; bytes up to 21)
  2. US-ASCII (single byte)
  3. ISO-8859-1 (single byte; default)

Target Encoding

• Conducted at time of php passing data to xml handlers
• Target encoding initially set to same as source encoding
• Can be changed at any time

Characters not capable of source encoding cause an error

Characters not capable of target encoding are demoted (to “?”)