473,386 Members | 1,720 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,386 software developers and data experts.

I've a class method that dies on the line that it returns


I killed last night and a good chunk of today trying to figure out this
one particular attempt to get a class and initialize it. My code is
using a class method called getObject to include() a file and then
initialize the class in that file (one class per file, each file has
the same name as the class). This code has been working fine for 8
months, and now is dying on this one line.

Oddly, it is dying on the last return of this method.

I've been putting in a lot of echo statements to debug this method.
Everything seems to work till I uncomment that last line that returns.
Then the code dies.

I'm out of ideas. Any suggestions?



/**
* 11-27-04 - we want to save memory by having just one of each object,
where possible. It would cost too
* much memory and too much time if we created a new object every time
a class was called.
* Therefore this object keeps an array of all objects so far called,
and hands out references
* to them to the code that needs them. This method also enforces
security in that, before
* creating an object it checks the name of the class against the list
in arrayOfAllAllowedFunctions.php
* If the class isn't listed, this method won't create the object. This
method and import(), below,
* manage the including and initialization of all the classes and
functions that this code uses.
*
*
*
* public
* returns object
*/
function & getObject($nameOfClassToBeUsed="",
$nameOfFunctionOrClassCalling="", $noErrorImport=false,
$specialCaseImport=false) {
$this->notes("We are now at the start of getObject(), looking for
'$nameOfClassToBeUsed' which is being sought by
'$nameOfFunctionOrClassCalling'.");
if ($this->softwareIsFitToRun) {
if (!$nameOfClassToBeUsed) {
print "Awful sorry, the software wants to create a software object,
but it's just being handed an empty string instead of the correct name.
Problem in getObject(), in McControllerForAll.";
if ($nameOfFunctionOrClassCalling) print "<br><br>If you're the
programmer, then you may want to know that this code is being called
from $nameOfFunctionOrClassCalling for the source of the problem.";
return false;
}
// 10-29-03 we need to change this next line, because our server
runs an old version of PHP.
// if (array_key_exists($nameOfClassToBeUsed,
$this->arrayOfAllTheObjectsSoFarLoaded)) {
if
(isset($this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed])) {
// 01-28-05 - we want to run this line every single time something
it called, but
// to avoid redundancy we need to call it when import() is not
being called, because
// we're also going to call it in import().
$this->setTwoLevelsOfCode($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling);
$object = &
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed];
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
return $object;
} elseif (class_exists($nameOfClassToBeUsed)) {
// 10-13-03 - in the 2 lines above we look to see if an instance of
this class already exists in
// $this->arrayOfAllTheObjectsSoFarLoaded. If so, we want to return
it. But if not, then we want to see
// whether such a class is known of. If yes, then we create an
instance of it. If not, then we will skip down
// below and run import() in the hopes of finding it.
//
// 01-28-05 - we want to run this line every single time something
it called, but
// to avoid redundancy we need to call it when import() is not
being called, because
// we're also going to call it in import().
$this->setTwoLevelsOfCode($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling);
$object = new $nameOfClassToBeUsed();
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] = &
$object;
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
return $object;
} else {
$this->notes("In getObject(), in McControllerForAll, we will now
attempt to get a parent class for '$nameOfClassToBeUsed'.");
$gotten = $this->getParentClass($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling);
if ($gotten) {
$this->notes("In getObject(), in McControllerForAll, we have
gotten the parent class, if there was one, for '$nameOfClassToBeUsed'.
We will now try to import the class.");
// 10-10-03 - hopefully this method doesn't get this far because
the needed object has already been found
// and the "return" keyword has stopped execution of the method.
But if we get this far, then we run import
// because we've got to find this object

echo "<p> we'd like to get '$nameOfClassToBeUsed' right now.";

$imported = $this->import($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling, $noErrorImport, $specialCaseImport);
echo "<p> imported is: $imported ";
// 10-13-03 - now that we've run import() we try again to see if
this class exists
$this->notes("We tried to import the class '$nameOfClassToBeUsed'.
The result was '$imported'.");
echo "<p> hello";
if (class_exists($nameOfClassToBeUsed)) {
echo "<p> the class exisits ";
$object = new $nameOfClassToBeUsed();

echo "<p> now we probably have have an object ";

$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] = &
$object;
$this->notes("In getObject(), in McControllerForAll, we imported
the class '$nameOfClassToBeUsed' and we will now call setCallingCode()
on it. The calling class is '$nameOfFunctionOrClassCalling'.");

echo "<p> let's test this object ";

if (is_object($object)) {
echo "now we will call setCallingCode ";
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
echo "okay, we've called setcallingcode ";
return $object;
// } else {
// $this->error("In getObject(), we were suppose to get the class
'$nameOfFunctionOrClassCalling' but even though the class existed we
were not able to get an object.");
}
} else {
$this->error("$nameOfClassToBeUsed not found. The code that wants
this class is $nameOfFunctionOrClassCalling ");
}

}
}
}
}

Jul 21 '05 #1
10 1624
On 21 Jul 2005 11:24:53 -0700, lk******@geocities.com wrote:
This code has been working fine for 8
months, and now is dying on this one line.

Oddly, it is dying on the last return of this method.

I've been putting in a lot of echo statements to debug this method.
Everything seems to work till I uncomment that last line that returns.
Then the code dies.

I'm out of ideas. Any suggestions?


Define "dies". Error messages?

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 21 '05 #2
>>This code has been working fine for 8
months, and now is dying on this one line.

Oddly, it is dying on the last return of this method.

I've been putting in a lot of echo statements to debug this method.
Everything seems to work till I uncomment that last line that returns.
Then the code dies.

I'm out of ideas. Any suggestions?


Define "dies". Error messages?


None that appear on screen. Check out
http://www.publicdomainsoftware.org/

Jul 21 '05 #3
On 21 Jul 2005 11:46:23 -0700, lk******@geocities.com wrote:
Define "dies". Error messages?


None that appear on screen. Check out
http://www.publicdomainsoftware.org/


andyh@server:~$ GET http://www.publicdomainsoftware.org/
500 Server closed connection without sending any data back

Check the Apache error log. Odds are something's dumped core.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 21 '05 #4

At the top of my script I've this:

error_reporting(E_ALL);

I've commented out nearly my whole script save for the initialization
of McControllerForAll and then these lines:


$this->resultsObject = & $this->getObject("McResults",
"McControllerForAll", true, true);

echo "<p>wonderful";
$this->notifyObject = & $this->getObject("SingletonNotify",
"McControllerForAll", true, true);

echo "<p>awesome";
flush();



You can see the getObject() method below. It dies on this line:

if (is_object($object)) return $object;

If I comment out that line then I can get the word "awesome" to my
screen.

I'm out of ideas about what else to test. The error checking is already
fairly comprehensive.


/**
* 11-27-04 - we want to save memory by having just one of each
object, where possible. It would cost too
* much memory and too much time if we created a new object every
time a class was called.
* Therefore this object keeps an array of all objects so far called,
and hands out references
* to them to the code that needs them. This method also enforces
security in that, before
* creating an object it checks the name of the class against the
list in arrayOfAllAllowedFunctions.php
* If the class isn't listed, this method won't create the object.
This method and import(), below,
* manage the including and initialization of all the classes and
functions that this code uses.
*
*
*
* public
* returns object
*/
function & getObject($nameOfClassToBeUsed="",
$nameOfFunctionOrClassCalling="", $noErrorImport=false,
$specialCaseImport=false) {
$this->notes("We are now at the start of getObject(), looking for
'$nameOfClassToBeUsed' which is being sought by
'$nameOfFunctionOrClassCalling'.");
if ($this->softwareIsFitToRun) {
if (!$nameOfClassToBeUsed) {
print "Awful sorry, the software wants to create a software
object, but it's just being handed an empty string instead of the
correct name. Problem in getObject(), in McControllerForAll.";
if ($nameOfFunctionOrClassCalling) print "<br><br>If you're
the programmer, then you may want to know that this code is being
called from $nameOfFunctionOrClassCalling for the source of the
problem.";
return false;
}
// 10-29-03 we need to change this next line, because our
server runs an old version of PHP.
// if (array_key_exists($nameOfClassToBeUsed,
$this->arrayOfAllTheObjectsSoFarLoaded)) {
if
(isset($this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed])) {
// 01-28-05 - we want to run this line every single time
something it called, but
// to avoid redundancy we need to call it when import() is
not being called, because
// we're also going to call it in import().
$this->setTwoLevelsOfCode($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling);
$object = &
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed];
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
return $object;
} elseif (class_exists($nameOfClassToBeUsed)) {
// 10-13-03 - in the 2 lines above we look to see if an
instance of this class already exists in
// $this->arrayOfAllTheObjectsSoFarLoaded. If so, we want
to return it. But if not, then we want to see
// whether such a class is known of. If yes, then we create
an instance of it. If not, then we will skip down
// below and run import() in the hopes of finding it.
//
// 01-28-05 - we want to run this line every single time
something it called, but
// to avoid redundancy we need to call it when import() is
not being called, because
// we're also going to call it in import().
$this->setTwoLevelsOfCode($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling);
$object = new $nameOfClassToBeUsed();

$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] = &
$object;
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
return $object;
} else {
$this->notes("In getObject(), in McControllerForAll, we
will now attempt to get a parent class for '$nameOfClassToBeUsed'.");
$gotten = $this->getParentClass($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling);
if ($gotten) {
$this->notes("In getObject(), in McControllerForAll, we
have gotten the parent class, if there was one, for
'$nameOfClassToBeUsed'. We will now try to import the class.");
// 10-10-03 - hopefully this method doesn't get this far
because the needed object has already been found
// and the "return" keyword has stopped execution of the
method. But if we get this far, then we run import
// because we've got to find this object
$imported = $this->import($nameOfClassToBeUsed,
$nameOfFunctionOrClassCalling, $noErrorImport, $specialCaseImport);
// 10-13-03 - now that we've run import() we try again
to see if this class exists
$this->notes("We tried to import the class
'$nameOfClassToBeUsed'. The result was '$imported'.");
if (class_exists($nameOfClassToBeUsed)) {
$object = new $nameOfClassToBeUsed();
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] = &
$object;
$this->notes("In getObject(), in McControllerForAll,
we imported the class '$nameOfClassToBeUsed' and we will now call
setCallingCode() on it. The calling class is
'$nameOfFunctionOrClassCalling'.");
if (is_object($object)) {
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
echo "<p>the world is a good place ";
if (is_object($object)) return $object;
} else {
$this->error("In getObject(), we were suppose to
get the class '$nameOfFunctionOrClassCalling' but even though the class
existed we were not able to get an object.");
}
} else {
$this->error("$nameOfClassToBeUsed not found. The
code that wants this class is $nameOfFunctionOrClassCalling ");
}

}
}
}
}

Jul 21 '05 #5
> Check the Apache error log. Odds are something's dumped core.

What does that mean, to say that something has dumped core?

Jul 21 '05 #6
On 21 Jul 2005 12:25:26 -0700, lk******@geocities.com wrote:
Check the Apache error log. Odds are something's dumped core.


What does that mean, to say that something has dumped core?


http://en.wikipedia.org/wiki/Core_dump

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 21 '05 #7
>>> Check the Apache error log. Odds are something's dumped core.

What does that mean, to say that something has dumped core?


http://en.wikipedia.org/wiki/C ore_dump


Has this sort of thing ever happened to you while working with PHP?
What sort of things trigger it?

Jul 21 '05 #8
Oh my god, what a rotten day. 9 hours debugging to find I'd inflicted
an infinite loop on myself:
function notes($message="") {
if (is_object($this->resultsObject)) {
$this->notes($message);
}
}
Somehow I took out the member object:
function notes($message="") {
if (is_object($this->resultsObject)) {
$this->resultsObject->notes($message);
}
}

I guess that does it for me and my resistance to IDE's. Is there an IDE
that catches infinite loops? I'd pay very good money to avoid ever
going through what I went through last night and this morning again.

Jul 21 '05 #9
On 21 Jul 2005 14:49:22 -0700, lk******@geocities.com wrote:
Check the Apache error log. Odds are something's dumped core.

What does that mean, to say that something has dumped core?
http://en.wikipedia.org/wiki/C ore_dump


Has this sort of thing ever happened to you while working with PHP?


Rarely, but sometimes.
What sort of things trigger it?


From most common to least, bugs in compiled PHP extensions, the libraries they
load, PHP itself, or Apache.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 21 '05 #10
On 21 Jul 2005 14:56:00 -0700, lk******@geocities.com wrote:
Oh my god, what a rotten day. 9 hours debugging to find I'd inflicted
an infinite loop on myself:
function notes($message="") {
if (is_object($this->resultsObject)) {
$this->notes($message);
}
}
Somehow I took out the member object:
function notes($message="") {
if (is_object($this->resultsObject)) {
$this->resultsObject->notes($message);
}
}

I guess that does it for me and my resistance to IDE's. Is there an IDE
that catches infinite loops? I'd pay very good money to avoid ever
going through what I went through last night and this morning again.


Don't bother. You won't ever do that again.

Jul 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil Powell | last post by:
function setTableStr($tableRefName) { // VOID "METHOD" SEE NOTE BELOW /*-------------------------------------------------------------------------- --- This function will set the class property...
11
by: Bob Rock | last post by:
Hello, I'd like to be able to allow instanciation of a class (class Class_A) only from another class method (class Class_B). And I'd like to write the necessary code to enforce this behavior...
6
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: comp.lang.php | last post by:
class ThumbView extends PaginationView { function ThumbView() {} /** * Determine if the original image is actually an image and thus a thumbnail can be generated at all * * @access public...
7
by: DemonWasp | last post by:
I've been having some trouble getting the Scanner class to operate the way I'd like. I'm doing some fairly basic file IO and I can't seem to get the class to load the last line/token any way I try....
0
by: alwayssmiling | last post by:
hi, I created an abstract class. In that a method which returns same class object, like predifned class, system.drawing.image a = system.drawing.image.fromfile(filename) this...
3
by: MD | last post by:
Hi, I have a variable which is defined inside a class method. When I call PyModule_GetDict on the module containing this class, the dictionary doesn't contain any information about this...
4
by: sjkothenbeutel | last post by:
I've been reading through quite a bit regarding this topic but am finding myself confused. Here is the scenario: I have a javascript class defined with methods whereas each has references to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.