ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Developing Web Services Using PHP
Subject:   Using a class instead of explicit function mapping
Date:   2007-08-02 14:28:50
From:   Ed_D
Being that PHP is moving more and more to object-oriented programming, it might be a good idea to recommend that developers use a class map. Define all of the external functions in a class that is then associated with the service.


For example:


class External{
public function getCatalogEntry{...}
}


$server->setClass('External');
$server->handle();



There are several advantages to this approach:


- easier to add/remove functions
- the functions are not in global scope
- when handling SOAP Headers (which are handled as a function call prior to the "actual" function), you can store a value from the header, eg a session id, as an instance variable
- you can use class constants for return/fault codes
- classes make maintaining versions of your service easier (eg use a name like External_1_1). A minor revision upgrade might only mean you need to extend the class and modify a single function (eg External_1_2 extends External_1_1).



Just my 2 cents.