By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,716 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,716 IT Pros & Developers. It's quick & easy.

Two identical class methods, one produces segfault

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Take out all the references (replacing =& with =) and see what happens.

"Phil Powell" <ph**************@gmail.com> wrote in message
news:b5**************************@posting.google.c om...
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

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.