The Artima Developer Community
Sponsored Link

PHP Buzz Forum
include_once / require_once Wrapper Class optimized

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Pure-PHP

Posts: 20
Nickname: purephp
Registered: Mar, 2005

Pure-PHP is kind of Blog about PHP, and unconventional methodes to boost PHP-apps
include_once / require_once Wrapper Class optimized Posted: Mar 25, 2005 1:59 PM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Pure-PHP.
Original Post: include_once / require_once Wrapper Class optimized
Feed Title: Pure PHP - PHP unconventional
Feed URL: http://www.iran-fun.com/
Feed Description: Unconventional methodes to boost php apps
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Pure-PHP
Latest Posts From Pure PHP - PHP unconventional

Advertisement

When I posted my Idea of building a wrapper class for include_once and require_once, I didn't think, that the many php developer would like it. But I was wrong, fortunately.

Thanks to Mathias Taylor for benchmarking. Special thanks goes to Cristian Strian for his suggestion to optmize the class, and make it faster. That is the optimized wrapper class.

Usage:

<?php

require("includeWrapper.class.php");
includeWrapper::includeOnce("test.php");
includeWrapper::includeOnce("test.php");
includeWrapper::includeOnce("test.php");
print_r(includeWrapper::getPaths());
?>

Output:
Array
(
[test.php] => 1
)

The class itself.

<?php

class includeWrapper{
    
public static $paths = array();
    
public static function includeOnce($path_file){
        if(!isset(
self::$paths[$path_file])){
            include(
$path_file);
            
self::$paths[$path_file] = true;
        }
    }
    
public static function requireOnce($path_file){
        if(!isset(
self::$paths[$path_file])){
            require(
$path_file);
            
self::$paths[$path_file] = true;
        }
    }
    
// just for testing
    
public static function getPaths(){
        return
self::$paths;
    }
}
?>

Read: include_once / require_once Wrapper Class optimized

Topic: Fatal Error is the Fatal Error of PHP - How to avoid it Previous Topic   Next Topic Topic: Magic Quotes are Worthless

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use