473,329 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,329 software developers and data experts.

class_exists and autoload

code green
1,726 Expert 1GB
A while ago I decided I like the idea of __autoload
or what seems to be better spl_autoload_register(),
so now all my projects use this.

But a major problem arises using third party classes that make use of class_exists().
Because class_exists will call autoload if the class has not been defined
and autoload has.
So unless your autoload function can map in the directory structure of the third party class a critical error occurs

This is the most idiotic thing I have come across in PHP.
Why should class_exists have the potential to crash a program?

Has anybody found a suitable work-around for this bug that PHP DENY is a bug? http://bugs.php.net/bug.php?id=47001
Dec 23 '09 #1
6 7604
kovik
1,044 Expert 1GB
My workaround is manually including files that are needed, and ignoring files that are not. It makes your code easier to follow. I, for one, am against the idea of the __autoload magic method.
Dec 23 '09 #2
Dormilich
8,658 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. class_exists("yourClass", false);
__________________
reading the manual actually pays off.....
Dec 24 '09 #3
code green
1,726 Expert 1GB
Dormilich
class_exists("yourClass", false);
reading the manual actually pays off.....
I am aware of this Dormilich, but I don't use class_exists(), it is used in a third party class, JPGRAPH to be precise.
These class_exists() calls are all over the place, and causing problems.

kovik,
I, for one, am against the idea of the __autoload magic method.
it is actually spl_autoload_register() I use now, this allows the use of multiple 'autoload' functions and is reportedly less overhead.
My workaround is manually including files that are needed, and ignoring files that are not. It makes your code easier to follow
Well, that is debatable.
I have some big projects where scripts may be called via a web-page or from a scheduled task or even from another project, using a combination of classes for MySql, MsSql, CSV/XLS, PDF, FTP......

I had includes all over the place, in fact include_once was mandatory.
spl_autoload_register() made the code easier to manage.
I know the command 'new' will invoke a class without worrying where it is included.
Much simpler if you are comfortable with classes.
Dec 24 '09 #4
Dormilich
8,658 Expert Mod 8TB
but I don't use class_exists(), it is used in a third party class, JPGRAPH to be precise.
These class_exists() calls are all over the place, and causing problems.
I admit, changing the class_exists() calls is tedious and bad style, though it would handle the problem, right?

very tedious after looking at the website… did you mention that to the JpGraph developers?
Dec 24 '09 #5
code green
1,726 Expert 1GB
did you mention that to the JpGraph developers?
Its a thought. I have no doubt they will defend their reasoning.

I don't like the idea of editing the classes but I like this idea instead of class_exists
Expand|Select|Wrap|Line Numbers
  1. if(in_array($class_name, get_declared_classes()));
I may place additional code in my autoloader function that handles jpgraph classes
Dec 24 '09 #6
dlite922
1,584 Expert 1GB
If you have a good IDE, you can run a replace-all with regex for all files in the JpGraph directory.

PHPED does this for me and shows me all the instances that it replace so I can quickly view any mistakes if any.

It's quick, but dirty. You'd have to do this every time you upgrade the app, but then again how often is that really?




Dan
Dec 24 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Matt Ittigson | last post by:
I'm getting the following error(s) running perlcc and can't find any explanation or work around. I'm including the errors and the script itself. I get the same errors on a cygwin+Win2k box as a...
1
by: Jim Schueler | last post by:
Here is some sample code that uses inherited class methods: package parseHTML ; sub parseHTML::docomment { my $comment = shift ; print $comment, "\n" ; }
3
by: alejandro.rivero | last post by:
In Mozilla, the following code seems to resize correctly the IFRAME, so no scroll bars: <iframe marginwidth=0 marginheight=0 src=text.html onload="this.height= this.contentDocument.height">...
4
by: CompGeek | last post by:
Hi there, I am trying to load a file with 1729 records into a DB2 UDB EEE 7.1 DataBase (on AIX 4.3) which is across two partitions. The partitioning key is BI_INSTITUTIONAL_KEY which is a BIGINT...
0
by: Thomas Mlynarczyk | last post by:
Hi, Having experimented with the spl_autoload functions, the following questions came to my mind: 1) In which order are the possible path/extension combinations tried by spl_autoload()? It...
0
by: turnitup | last post by:
I don't suppose anyone can suggest a PHP referencer that can parse a program that uses the __autoload function?
3
natalie99
by: natalie99 | last post by:
Hello everyone Progress on my project is going well, mostly thanks to everyone here's help :D The last stage of the first stage (you know what I mean) is this: I want to do either of the...
3
realin
by: realin | last post by:
hiya guys its been long since i posted here .. well i am using pattemplate which is a template tool for website development. But in my website's structure i have placed all my classes into a...
4
by: robertallenpayne | last post by:
I have been asked to develop an application in Access for work. This application must have a simple user interface because the folks using it are not "database people" - their words, not mine. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.