autoload

Using the ZF autoloader to load models

I have a simple ZF application (no modules) which works fine when I require classes before I use them. However, I'd like to use the ZF autoloader to load them automatically (which I assumed was default behaviour). How would I go about doing this? I'm a bit confused by the new(ish) Zend_Application way of doing things. My directory struc...

__autoload disaster - conflicts with Joomla

I have just changed all my code to use __autoload to find that it conflicts with the joomla autoloader. I integrate my app with joomla in some cases to register users etc. I found spl_autoload_register() with aparently allows many autoloaders. What should I do? update: this is what joomla does Loads this file from /library/loader.ph...

Zend Framework: Loading modules from another directory

Hey there guys, this is my first question on Stack Overflow. I figured this website has helped me alot so I give it a shot as well. I'm currently working on multiple Zend Framework applications that need to inherit modules from a common module directory. The file structure used is the conventional method (omitting actual names and refer...

PHP Namespaces: Function Loading

Hi, I'd like to play a bit with functional programming in PHP. I think it's intersting to try out something different when always writing oop in php. However, I'd like to use namespaces. My namespaces are equal to the file structure: namespace my\Models\User; /my/Models/User.php Is their a way to do something like autoloading for th...

Getting Textmate to create PHP autoload class name from filepath

What I would like is a snippet that when executed, grabs the TM_FILEPATH output Explodes it on the slash / Then split out each part as a placeholder containing that part and an underscore (apart from the last part (the filename)) For Example: for a file in directory path /Path/To/Original/file we would get class ${1:Path_}${2:To_}${3:Or...

Rails 3: how to load files in /lib?

I'm new to rails and making some sort of noob mistake: I frequently need to count the number of lines in a file, so I'm trying to monkey patch class File like this: class File def self.line_count( filename ) %x{wc -l #{filename}}.split.first.to_i end end I saved this to /lib/file_util.rb. I thought that this was supposed to...

PHP autoloading: Preventing 'cannot redeclare <class>' in all constellations?

Question Is there a way I can make PHP ignore re-declarations of classes rather than barf up a FATAL ERROR? Or at least throw an exception? (I could easily catch it then and proceed (as well a log the attempted autoloading).) I'm guessing no and a fatal error is a fatal error - after all, in ninety-nine out of a hundred cases, that's r...

zend framework include another class in my action controller

I am newbie in zend framework , a simple question : in my IndexController file , I want to instance new class. I put the file of class declaration under /library and of course its in the include path (index.php) set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path() ))...

[PHP+ModalBox] require_once problem

Hello to everybody! I have this code in the __constructor $this->Reliability = new Reliability("name","url"); Problem: I got an unexpected strange error: Fatal error: Class 'Reliability' not found in "/path/" I'm using the "__autoload" method to call the required classes, but it doesn't work when I'm calling the file in a ModalB...

Can PHP __autoload() a class from within another __autoload() of the same class?

OK, this is a tough one... I think, and I have a feeling the answer is simply no, but in that case I would like some answers for alternatives. I have a very complex __autoload() function in a framework which can dynamically create classes. There a three classes required in order for the dynamic creation of a class called AuthActions --...

How to disable autoload in jqGrid?

Hi! How to disable autoload in jqGrid and load data manually when I need it? Thanks. ...

Writing a Bulletproof __autoload Function for PHP

I'm trying to define my PHP __autoload function to be as bulletproof and flexible as possible. Here's the breakdown of my application's structure: /dev (root) /my_app /php /classes - Class1.php - Class2.php - Class3.php /scripts myscript.php (th...

include path and the __autoload function in php

Hey everyone, I am trying to convert several php scripts to use the __autoload function. Right now I can use the include and require functions like this: require_once('path/to/script.php'); But inside of the __autoload function, I can't use the line above. I have to use this: require_once('absolute/path/to/script.php'); Why does...

Question about a simple PHP Autoloader

I was just learning aboutt PHP namespaces and starting to create a simple autoload function. What O did was: function __autoload($name) { echo $name . "<br />"; require_once $name . ".php"; } So, this works if I do not use any aliasing or importing statements eg. use MainNamespace\Subnamespace because if I did that, assuming i hav...

Dealing with PHPUnit path issues.

I am getting the following error when I try to run PHPUnit from within my current MVC framework application Fatal error: Cannot redeclare class PHPUnit_Util_FilterIterator in /usr/local/pear/PHPUnit/Util/FilterIterator.php on line 162 I've managed to trace that error to a combination of a few things. $paths = array(); $paths[] = '../...

PHP __autoload performance

I have a script that uses autoload to load classes that arn't found. I don't deliberately include file though i can but i would like the autoload function to include the required files , because the script can be recursive that is if the class is already loaded i don't want to check the corresponding file is loaded and if class_exist on ...

Best way to load module/class from lib folder in Rails 3?

Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore, what would be the best way to load them? From github: A few changes were done in this commit: Do not autoload code in *lib* for applications (now you need to explicitly require them). This makes an application behave closer to an engine (code...

PHP - How to be able to use variables inside __autoload() function

The autoload function I am using is as follows:- function __autoload($moduleName) { //Logic to check file existence- include if exists else redirect to fallback page } Does it not take any other arguments? I want to perform some logic based on some variables inside the autoload function. How do I do it without the use of global ...

function __autoload & using require_once / ignore certain instances

Hi everyone, I am using the autoload function for a certain library... But I am trying to implement Doctrine and I am getting a 500 Internal Server Error. I believe its because I am creating = new instance and in the autoload... It checks a different directory. Is there a way to create new instances of classes that will ignore the au...

Any way to avoid loading unused classes for a non-oo app?

My application uses a 'central' page controller that grabs a bunch of files (I hesitate to say libraries) each containing a few related classes, using require_once, before fetching the request. As in: require_once (dir_lib . 'db.php'); require_once (dir_lib . 'uuid.php'); require_once (dir_lib . 'data.php'); ...