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

Two identical class methods, one produces segfault

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
1 1559
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil Powell | last post by:
<? class ErrorMsgCollection { var $name; var $mandatory; var $emptyErr; var $maxLength; var $maxLengthErr; var $minLength; var $minLenghtErr;
0
by: Phil Powell | last post by:
URL: http://valsignalandet.com/cookiegrab.php?name=valIdentifier This page produces a cookie value and sends it back as HTML using PHP and Javascript to obtain it. This URL will be used as the...
1
by: Jing You | last post by:
hi every one, I have got some confused problem when I try to write some custom object by javascript. Look at the example code here: <BODY> <script language="jscript">
8
by: LAvoisieR | last post by:
Following test code behaviour suprised me and I dont know what's wrong with this. I have two overloaded constructors within base class and virtual destructor implemented. Derived class uses...
4
by: Peter Speybrouck | last post by:
I have a little problem with a webservice. I reproduced the problem in the following simplified example. I just create a new C# ASP.NET webservice and a c# console application. I added a new...
48
by: phillip.s.powell | last post by:
MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask) I have database Spring with table Students I have database Summer with table Students I am tasked to produce a...
3
by: ad | last post by:
I have a web application which refer a class library project. The web application have a web.config and the class library project have a app.config. They all have connection string defined in...
7
by: comp.lang.php | last post by:
<? class EditResultGenerator extends MethodGeneratorForActionPerformer { /** * Create an instance of itself if $this does not yet exist as an EditResultGenerator class object * * @access...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.