The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Native php classes and autoload
Discuss Native php classes and autoload in the PHP Development forum on Dev Shed. Native php classes and autoload PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 5th, 2013, 07:36 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
|
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?
|

February 5th, 2013, 08:17 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

February 5th, 2013, 09:06 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
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.
|

February 5th, 2013, 10:02 AM
|
 |
Contributing User
|
|
Join Date: Dec 2012
Location: Chicago
Posts: 49
Time spent in forums: 17 h 32 m 9 sec
Reputation Power: 1
|
|
Excerpt from: http://www.php.net/manual/en/book.fileinfo.php
Quote: 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.
|

February 5th, 2013, 10:15 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

February 5th, 2013, 04:26 PM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
They were doing that,
and no, it wasn't available. It is now, and here's why:
Quote: | 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!
|

February 6th, 2013, 08:06 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|