471,624 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 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 1541
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Phil Powell | last post: by
5 posts views Thread by Nick Flandry | last post: by
7 posts views Thread by DemonWasp | last post: by
4 posts views Thread by sjkothenbeutel | last post: by
reply views Thread by leo001 | last post: by

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.