#1
  1. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123

    Native php classes and autoload


    I have included a third party library in my application.

    part of this library checks to see if the finfo class is available. I'm guessing not as this is then calling my autoload function

    is there any way to prevent user-land autoload functions from being executed when we know the class doesn't exist?
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Are you not running PHP 5.3+? It's available there.

    You can't prevent the autoloader "when you know the class doesn't exist," because that's the whole point of auto-loaders: they run when a class is not found.

    You can hard-code an exception for finfo into your autoloader, but if your third party script relies on it you should upgrade or stop using that script.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    I'm actually running 5.4.7 locally on my windows computer, where I'm developing....and the finfo class doesn't seem to be there... very odd, I thought it would be

    EDIT

    there is no class called "finfo", not according to the manual.....maybe I need some other library class that uses the finfo_* functions (which I don't have either?????)

    having a bad day
    Last edited by Northie; February 5th, 2013 at 09:10 AM.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  6. #4
  7. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    106
    Rep Power
    4
    Excerpt from: http://www.php.net/manual/en/book.fileinfo.php

    File Information

    Introduction
    Installing/Configuring
    Requirements
    Installation
    Runtime Configuration
    Resource Types
    Predefined Constants
    Fileinfo Functions
    finfo_buffer Return information about a string buffer
    finfo_close Close fileinfo resource
    finfo_file Return information about a file
    finfo_open Create a new fileinfo resource
    finfo_set_flags Set libmagic configuration options
    Looks like it is in the manual.
    I have no idea why it is not loading for you.
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Northie, what's the code that's causing your autoloader to fire? Do they say:

    if( class_exists('finfo') )

    That returns true for me on 5.3.10 locally on my dev box.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    They were doing that,

    and no, it wasn't available. It is now, and here's why:

    Originally Posted by php.net
    Windows users must include the bundled php_fileinfo.dll DLL file in php.ini to enable this extension.
    It seems the extension was commented out of my local php.ini file.

    When in 'DEV' mode my autoload function scans the file system and compiles a list of all classes, functions, interfaces and namespaces, which is then cached for future use. The intention was that I could easily maintain a list of classes to use without having to do it manually and without exposing directory scanning attacks at a URL level (URLs generally map to some class to be included).

    So, when a class does not exist this scanning and compiling happens; which is expensive and I was noticing 10 second load times and xdebug cachegrind files of 65Mb (rather than my app's norm of ~350Kb)

    Thanks for all the help!
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Autoload normally tries to find a class based on class name. I've always organized it like this.

    classname: devshed_user_module_controller
    filename: Code/DevShed/User/Modules/Controller.php

    A full system scan every time seems really expensive, though if it's cached I guess it's not as bad.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo