Results 1 to 6 of 6

Thread: What are an Autoloading Classes in PHP?

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    What are an Autoloading Classes in PHP?

    Hi friends,
    I have just started with the PHP programming language. Since I am new to this language, I don't know much about it. I want to know about an auto-loading classes that are present in PHP. So I thought that someone hanging out there might be interested in helping me.!! Please explain me what are an Autoloading Classes in PHP? Any other useful information related to the topic would be appreciable.!!
    Technology is a way of organizing the universe so that man doesn't have to experience it.-- Max Frisch 1911 -1991

  2. #2
    Join Date
    Aug 2006
    Posts
    227

    Re: What are an Autoloading Classes in PHP?

    Many developers who create object-oriented applications, create a source file for class definition. The major drawback of this method is having to write a long list of includes file classes at the beginning of each script for an inclusion class. In PHP 5, this is no longer necessary. You can define the function __autoload () which will automatically be called if a class is not defined at the time of use. With it, you have one last chance to include a definition of class before PHP fails to declare a mistake. Hope that you understood the concept of the autoloading class.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  3. #3
    Join Date
    Jul 2006
    Posts
    442

    Re: What are an Autoloading Classes in PHP?

    Prior to PHP 5.3.0, the exception thrown from the function autoload could not be intercepted by a block catch and caused a fatal error. Since PHP 5.3.0 +, they can be intercepted in wrestling, to an accuracy close: If you throw a custom exception, then the class of that exception must be available. autoload Function must be used recursively to automatically load the class of the custom exception. PHP 5 has an exception model similar to that of other programming languages. An exception can be thrown ( "throw") and caught ( "catch") in PHP. The code must be surrounded by a try block to facilitate the entry of potential exceptions.
    "When they give you ruled paper, write the other way..." J.R.J.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: What are an Autoloading Classes in PHP?

    You should also keep in mind that autoloading is not available if using PHP in interactive mode CLI. The CLI SAPI was released for the first time with PHP 4.2.0, but it was experimental and had to be explicitly enabled with - enable-cli when running. / Configure script. The Windows packages between PHP 4.2.0 and PHP 4.2.3 distributed the CLI as php-cli.exe and let the CGI as php-cli.exe in the same directory. Since PHP 4.3.0 the Windows package distributes the CLI as php.exe in a separate folder named cli, so cli / php.exe. Since PHP 5, the CLI is installed in the main directory as php. exe. The CGI version is called when php-cgi.exe.
    Signatures reduce available bandwidth

  5. #5
    Join Date
    Aug 2006
    Posts
    235

    Re: What are an Autoloading Classes in PHP?

    I have provided an example of the autoload (), that may help you in understanding more better :
    PHP Code:
    <?php
    function autoload($class_name) {
        require_once 
    $class_name '.php';
    }
     
    $obj  = new MyClassDemo1();
    $obj2 = new MyClassDemo2(); 
    ?>
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  6. #6
    Join Date
    Nov 2008
    Posts
    996

    Re: What are an Autoloading Classes in PHP?

    The following is an example for autoloading with exception handling for 5.3.0+, hope that helps you :
    PHP Code:
    <?php
    function autoloaddemo($name) {
        echo 
    "Want to load $name.\n";
        throw new 
    Exception("Not able to load $name.");
    }
     
    try {
        
    $obj = new NonLoadableClass();
    } catch (
    Exception $e) {
        echo 
    $e->getMessage(), "\n";
    }
    ?>

Similar Threads

  1. What are objects and classes in C++?
    By Tionontati in forum Software Development
    Replies: 3
    Last Post: 28-12-2010, 08:46 AM
  2. Problem with Inner classes
    By Captain Carrot in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 02:14 PM
  3. Use of abstract classes
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 09:07 AM
  4. C # using classes in C + +
    By klite in forum Software Development
    Replies: 3
    Last Post: 01-10-2009, 10:15 AM
  5. Classes in VB.NET
    By Samir_1 in forum Software Development
    Replies: 2
    Last Post: 10-04-2009, 12:07 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,934,387.91872 seconds with 17 queries