Home arrow PHP arrow Page 3 - Enhancing a URL Handling Helper Class in PHP 5

Declaring the methods of the URL helper class static - PHP

Are you a PHP developer wishing to find an approachable guide that walks you through building different kinds of helper classes in PHP 5? Then look no further, because this group of articles may be the material that you really need.

  1. Enhancing a URL Handling Helper Class in PHP 5
  2. Review: generating dynamic URLs simply
  3. Declaring the methods of the URL helper class static
  4. Putting the new URL helper class in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
August 10, 2009

print this article



As I anticipated in the section that you just read, the next step I'm going to take to enhance the previous URL helper class will consist of declaring its implemented methods static, which makes it easy to call them without having to spawn an instance of the class in question.

That being said, please take a look at the modified version of the URL helper class, which has been included below. Here it is:

class URLHelper


// constructor not implemented

public function __construct(){}


// get web server root

public static function get_document_root()





// get script URL

public static function get_script_url()


return $_SERVER['PHP_SELF'];



// get script query string

public static function get_query_string()





// get request URI

public static function get_request_uri()





// get script file name

public static function get_script_filename()





// get request method

public static function get_request_method()


return strtolower($_SERVER['REQUEST_METHOD']);




Naturally, if you're anything like me, then it's possible that you didn't notice any big differences in the way that the above helper class has been defined. However, in this case the class's methods now have been declared static, in this way introducing the aforementioned benefits.

Since the modification of the signature of the helper class should be pretty easy for you to follow, it's time to develop a few illustrative examples to demonstrate how to take advantage of its functionality by calling its methods out of the object scope.

Want to see how these examples will be created? Then read the following segment. We're almost finished!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: