PHP Classes

Magic PHP Auto-Instantiator: Include and create objects with a single command

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (2 months ago) RSS 2.0 feedStarStarStar 40%Total: 362 This week: 1All time: 6,884 This week: 560Up
Version License PHP version Categories
autoinstantiator 1The PHP License3.0PHP 5, Language
Description 

Author

This class can include classes and create objects with a single command.

It registers an error handler so when the PHP engine finds a line in PHP code in the form of directory.subdirectory.class; it triggers an error notice that calls the registered error handler.

The error handler loads the PHP script that triggered the error and parses the code to determine the directory path of the class file to be included.

Then the class creates an object stored in global variable of the specified class name.

Innovation Award
PHP Programming Innovation award nominee
June 2014
Number 6


Prize: One book of choice by Packt
Creating a new object usually requires to load the class file explicitly or using an auto-loader before creating an object of the loaded class.

This class provides a simpler solution that just requires a single line of code to automatically load the class and create an object of that class.

Manuel Lemos
Picture of Andoitz Jordan Marmolejo
  Performance   Level  
Name: Andoitz Jordan Marmolejo <contact>
Classes: 7 packages by
Country: Spain Spain
Age: 33
All time rank: 81618 in Spain Spain
Week rank: 411 Up13 in Spain Spain Up
Innovation award
Innovation award
Nominee: 3x

Winner: 2x

Example

<?php
/*

    MAGIC PHP AUTO-INSTANTIATOR
        Include and instantiate PHP Classes automatically only writing something like "folder.folder.class;" on your PHP script.
   
        When we play with PHP MVC programming we ever have to make a class instantiation,
        then we need an include and have to know the exactly path for the folders, create the class
        and after we need to remember the name of instantiated variables that we did before.
       
        With this class you will need to use only one line to do this. Ever we will have the same name
        for the instantiated variable, so.. its really easy for remember.
       
        Enviroment:
            - This class was tested with the next specified environment:
                Windows XP
                WAMP SERVER 2.4
                PHP 5.4.16
                Apache 2.4.4
       
        Example:
            Before:
                include('com/phpclasses/myClass.php');
                include('com/phpclasses/myClass2.php');
                include('com/phpclasses/myClass3.php');
               
                $myClass = new myClass();
                $myClass2 = new myClass2();
                $myClass3 = new myClass3();
               
                $myClass->example();
                $myClass2->example();
                $myClass3->example();
               
                * This code will create three classes and will call an example method for everyone.
           
            After:
                com.phpclasses.myClass;
                com.phpclasses.myClass2;
                com.phpclasses.myClass3;
               
                $myClass->example();
                $myClass2->example();
                $myClass3->example();
               
                * This code will make it more easy.
   
    This class is only a testing class based in other programming languages like Java or ActionScript:
        import java.util.*
   
    I dont really know the real performance using this class on a production enviroment.
    As i said this class is only a testing class, the real way can be to make an apache extension, more complete and tested.

    For more information and updates please visit: http://www.andoitz.com
   
*/

include("com/phpclasses/import.php");
com.phpclasses.myClass;
$myClass->example();
?>


Details

MAGIC PHP AUTO-INSTANTIATOR Include and instantiate PHP Classes automatically only writing something like "folder.folder.class;" on your PHP script. When we play with PHP MVC programming we ever have to make a class instantiation, then we need an include and have to know the exactly path for the folders, create the class and after we need to remember the name of instantiated variables that we did before. With this class you will need to use only one line to do this. Ever we will have the same name for the instantiated variable, so.. its really easy for remember. Enviroment: - This class was tested with the next specified environment: Windows XP WAMP SERVER 2.4 PHP 5.4.16 Apache 2.4.4 Example: Before: include('com/phpclasses/myClass.php'); include('com/phpclasses/myClass2.php'); include('com/phpclasses/myClass3.php'); $myClass = new myClass(); $myClass2 = new myClass2(); $myClass3 = new myClass3(); $myClass->example(); $myClass2->example(); $myClass3->example(); * This code will create three classes and will call an example method for everyone. After: com.phpclasses.myClass; com.phpclasses.myClass2; com.phpclasses.myClass3; $myClass->example(); $myClass2->example(); $myClass3->example(); * This code will make it more easy. This class is only a testing class based in other programming languages like Java or ActionScript: import java.util.* I dont really know the real performance using this class on a production enviroment. As i said this class is only a testing class, the real way can be to make an apache extension, more complete and tested. For more information and updates please visit: http://www.andoitz.com

  Files folder image Files  
File Role Description
Files folder imagecom (1 directory)
Accessible without login Plain text file index.php Example Main Script
Accessible without login Plain text file Readme.txt Doc. Readme document
Accessible without login Plain text file Readme.md Doc. Documentation

  Files folder image Files  /  com  
File Role Description
Files folder imagephpclasses (2 files)

  Files folder image Files  /  com  /  phpclasses  
File Role Description
  Plain text file import.php Class Main mphpai class
  Plain text file myClass.php Class Simple Example Class

 Version Control Unique User Downloads Download Rankings  
 80%
Total:362
This week:1
All time:6,884
This week:560Up
 User Ratings  
 
 All time
Utility:50%StarStarStar
Consistency:50%StarStarStar
Documentation:50%StarStarStar
Examples:50%StarStarStar
Tests:-
Videos:-
Overall:40%StarStarStar
Rank:3779