0

I got an error while running my code, it says call to a member function getBallparkDetailsStartDate() on a non-object.

if($projectStatusId == ProjectStatusKeys::BALLPARK_ACTIVE) {
            $ballpark = $this->ballparkDetailsHandler->getBallparkDetailsByProjectId($projectId);               
            $projectDetails["startdate"] = $ballpark->getBallparkDetailsStartDate();
            $projectDetails["enddate"] = $ballpark->getBallparkDetailsEndDate();
            $projectDetails["projectid"] = $projectId;
            $projectDetails["name"] = $ballpark->getBallparkDetailsBookingRef();
            $projectDetails["status"] = ProjectStatusKeys::BALLPARK_ACTIVE; 
        }

I got the error in this line: $projectDetails["startdate"] = $ballpark->getBallparkDetailsStartDate();

Here is my other code:

public function __construct($ballparkDetailsId, $project, 
        $ballparkDetailsBookingRef, 
        $ballparkDetailsStartDate, $ballparkDetailsEndDate, 
        $ballparkDetailsExpiryDate, $ballparkDetailsDescription, 
        $ballparkDetailsNotes) {
    $this->ballparkDetailsId = $ballparkDetailsId;
    $this->project = $project;
    $this->ballparkDetailsBookingRef = $ballparkDetailsBookingRef;
    $this->ballparkDetailsStartDate = $ballparkDetailsStartDate;
    $this->ballparkDetailsEndDate = $ballparkDetailsEndDate;
    $this->ballparkDetailsExpiryDate = $ballparkDetailsExpiryDate;
    $this->ballparkDetailsDescription = $ballparkDetailsDescription;
    $this->ballparkDetailsNotes = $ballparkDetailsNotes;
}

public function getBallparkDetailsId() {
    return $this->ballparkDetailsId;
}

public function getProject() {
    return $this->project;
}

public function getBankName() {
    return $this->getProject()->getBankName();
}

public function getBankRef() {
    return $this->getProject()->getBankRef();
}

public function getRegionName() {
    return $this->getProject()->getRegionName();
}

public function getProjectStatusName() {
    return $this->getProject()->getProjectStatusName();
}

public function getBallparkDetailsBookingRef() {
    return $this->ballparkDetailsBookingRef;
}

public function getBallparkDetailsStartDate() {
    return $this->ballparkDetailsStartDate;
}

public function getBallparkDetailsEndDate() {
    return $this->ballparkDetailsEndDate;
}

public function getBallparkDetailsExpiryDate() {
    return $this->ballparkDetailsExpiryDate;
}

public function getBallparkDetailsDescription() {
    return $this->ballparkDetailsDescription;
}

public function getBallparkDetailsNotes() {
    return $this->ballparkDetailsNotes;
}

public function getProjectId() {
    return $this->getProject()->getProjectId();
}

public function getProjectStatusId() {
    return $this->getProject()->getProjectStatusId();
}

}
?>

The last time I check this it ran well. But now I don't know what's wrong with this? Please help me find the error. Thanks.

3
  • it seems like a function get() is not in this list, and that is what the error refers to. Is there something else you aren't showing us? Commented Oct 16, 2012 at 11:25
  • @Jakub I've edited my post. That get() function is getBallparkDetailsStartDate() Commented Oct 16, 2012 at 11:27
  • @Jakub, in such case, error message will say that method is not member of class.This looks like null class instance instead of object instance is used. Commented Oct 16, 2012 at 11:28

2 Answers 2

1

Apparently

$ballpark = $this->ballparkDetailsHandler->getBallparkDetailsByProjectId($projectId);

is not returning a "ballpark" at all. Probably it is returning an error, or something like an empty array.

Try var_dump()'ing $ballpark immediately before the line that raises the error, and see what it contains (probably False, NULL, array() or something equally un-ballparky.

Then, inspect the ballparkDetailsByProjectId() function in the BallparkDetailsHandler.php file. At a guess, you might be passing an invalid (i.e. nonexistent, removed, etc.) $projectId.

Then you might rewrite the code with error checking:

if($projectStatusId == ProjectStatusKeys::BALLPARK_ACTIVE) {
        $ballpark = $this->ballparkDetailsHandler->getBallparkDetailsByProjectId($projectId);
        if (!is_object($ballpark))
            trigger_error("Error: bad project ID: '$projectId': $ballpark",
                E_USER_ERROR);

        $projectDetails["startdate"] = $ballpark->getBallparkDetailsStartDate();
        $projectDetails["enddate"] = $ballpark->getBallparkDetailsEndDate();
        $projectDetails["projectid"] = $projectId;
        $projectDetails["name"] = $ballpark->getBallparkDetailsBookingRef();
        $projectDetails["status"] = ProjectStatusKeys::BALLPARK_ACTIVE; 
    }

Then in the BallparkDetailsHandler.php file you could modify this code:

// Prepare query or die
if (!($stmt = $this->mysqli->prepare($query))
    return "Error in PREPARE: $query";

$stmt->bind_param("i", $projectId);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($ballparkDetailsBookingRef, $bankRef, $regionName,
     $projectStatusId, $projectStatusName,  $ballparkDetailsDescription,
     $ballparkDetailsNotes, $ballparkDetailsStartDate, $ballparkDetailsEndDate,
     $ballparkDetailsExpiryDate);
$stmt->fetch();

// If no data, then die
if(!$stmt->num_rows)
    return "No data in DB for projectID '$projectId': $query";

// Should be clear sailing from here on. Actually I ought to check
// whether all these new() here do return anything sensible, or not

$bank = new Bank("", "", $bankRef, "");
$region = new Region("", $regionName, "");
$projectStatus = new ProjectStatus($projectStatusId, $projectStatusName);
$project = new Project($projectId, $bank, $region, $projectStatus);

return new BallparkDetails("", $project,
    $ballparkDetailsBookingRef, $ballparkDetailsStartDate, 
    $ballparkDetailsEndDate, $ballparkDetailsExpiryDate, 
    $ballparkDetailsDescription, $ballparkDetailsNotes);
Sign up to request clarification or add additional context in comments.

9 Comments

I tried var_dump() it says Warning: var_dump() expects at least 1 parameter, 0 given in C:\xampp\htdocs\RMS\classes\controller\ViewWorkloadController.php
Sorry, I meant: var_dump($ballpark);
@Iserni This is the whole code if you need to see it. codepad.org/xUbDxQR0
OK, it is not initializing the object. I checked your code, but the problem (if a problem exists, and not just a bad $projectId) lies in the BallparkDetailsHandler.php file.
Yes I removed something that I added. Please see my BallparkDetailsHandler.php here codepad.org/AFveZL54
|
0

$ballpark clearly doesn't contain the object you think it does on the line with the error. In fact, it obviously doesn't contain an object at all.

This implies that the preceding line (which sets $ballpark) isn't working properly. It would appear that it's returning a value that is is not an object.

I can't tell what that value is -- it could be null, or it could be an integer, string, array, etc. But whatever it is, it isn't a ballpark object.

I suggest you look at your getBallparkDetailsByProjectId() method to find the source of this problem.

1 Comment

Hello thanks for your reply. I tried var_dump() on it it says Warning: var_dump() expects at least 1 parameter, 0 given in C:\xampp\htdocs\RMS\classes\controller\ViewWorkloadController.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.