Two identical class methods, one produces segfault
From: Phil Powell (phillip.s.powell_at_gmail.com)
Date: 09/30/04
- Previous message: Rick Westmacott: "process management in windows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Sep 2004 16:38:35 -0700
Consider these two classes. Class Accepter in
placement_classes.inc.php works as a form validation object, and it
works like a charm:
PHP:
// placement_classes.inc.php - THIS ONE WORKS!
class Accepter {
function Accepter() {
$this->dbAP =& new DBActionPerformer();
$this->dbAP->connect();
$this->validate();
$this->dbAP->disconnect();
$this->dbAP = null;
}
/**
* Perform validation
*
* @access private
*/
function &validate() {
// STATIC VOID METHOD
foreach ($_POST as $key => $val) if (!isset(${$key}))
${$key} = $val;
$varErrArray = array();
array_push($varErrArray,
'placement_name|setMandatory~setMinLength~setMaxLe
ngth~setPattern|You must enter a location name~Your location name
must be 2 or more characters~Your location name must be 50 or fewer
characters in length~^(?!.*<[^>]+> )|Your location name configuration
is unrecognizable by our system, please re-enter with legitimate
characters|');
array_push($varErrArray, 'unique_key|setMandatory|You must
have a unique key prior to posting||');
/*---------------------------------------------------------------------------------------------------------------------
createErrorMsgCollection function from
formvalidation.inc standalone function returns an array of
ErrorMsgCollection
objects
-----------------------------------------------------------------------------------------------------------------------*/
$this->errorMsgObjArray =&
createErrorMsgCollection($varErrArray);
// CREATE FORM OBJECT PASSING ARRAY OF OBJECTS AS
PARAMETER
$this->formValidator =& new FormValidator('',
$this->errorMsgObjArray);
$this->isValid = $this->formValidator->isValid();
$this->setErrorArray($this->formValidator->getErrorArray());
$this->formValidator = null;
$this->errorMsgObjArray = null;
/*
if (strcmp(strtolower($action), 'add') == 0 ||
(strcmp(strtolower($action), 'edit') == 0 && $placement_name !==
$origPlacementName))
$this->checkDuplicatePlacement($placement_name);
// CHECK FOR DUPLICATE PLACEMENT
*/
}
}
This is the class Accepter from contacts_classes.inc.php and while it
is now identical in code structure to the Accepter classe in
placement_classes.inc.php, whenever this class method is invoked, all
processes stop (no errors), arrays are unfinished, objects are
unfinished, HTTP never produces, Apache goes down, literally
everything crashes!
PHP:
// contacts_classes.inc.php - THIS ONE PRODUCES A POSSIBLE SEG
FAULT!
class Accepter {
function Accepter() {
// NEW 8/17/2004: SURROUND validate() METHOD WITH
INSTANTIATION OF $this->dbAP OBJECT PROPERTY
$this->dbAP =& new DBActionPerformer();
$this->dbAP->connect();
$this->validate();
$this->dbAP->disconnect();
$this->dbAP = null;
}
/**
* Main method. Will perform all other validation methods and
set isValid boolean property
*
* @access public
*/
function &validate() { //
STATIC VOID METHOD
foreach ($_POST as $key => $val) if (!isset(${$key}))
${$key} = $val;
$varErrArray = array();
array_push($varErrArray,
'placement_name|setMandatory~setMinLength~setMaxLe
ngth~setPattern|You must enter a location name~Your location name
must be 2 or more characters~Your location name must be 50 or fewer
characters in length~^(?!.*<[^>]+> )|Your location name configuration
is unrecognizable by our system, please re-enter with legitimate
characters|');
array_push($varErrArray, 'unique_key|setMandatory|You must
have a unique key prior to posting||');
/*---------------------------------------------------------------------------------------------------------------------
createErrorMsgCollection function from
formvalidation.inc standalone function returns an array of
ErrorMsgCollection
objects
-----------------------------------------------------------------------------------------------------------------------*/
$this->errorMsgObjArray =&
createErrorMsgCollection($varErrArray);
// CREATE FORM OBJECT PASSING ARRAY OF OBJECTS AS
PARAMETER
$this->formValidator =& new FormValidator('',
$this->errorMsgObjArray);
$this->isValid = $this->formValidator->isValid();
$this->setErrorArray($this->formValidator->getErrorArray());
$this->formValidator = null;
$this->errorMsgObjArray = null;
/*
if (strcmp(strtolower($action), 'delete_select') == 0 &&
@sizeof($delete_selected) == 0) {
$this->isValid = false;
$this->setErrorArray(array('action' => 'You must select
at least one contact for deletion'));
}
*/
}
}
I've been trying to debug this for days now to no avail. I can verify
every object property is present and accounted for (and identical in
every way), but if you evoke one it's fine, the other and a segfault!
Help!
Thanx
Phil
- Previous message: Rick Westmacott: "process management in windows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|