سؤال

I am relatively new to PHP and having some decent success however I am running into this issue:

If I try to create a new instance of the class GenericEntryVO, I get a 500 error with little to no helpful error information. However, if I use a generic object as the result, I get no errors. I'd like to be able to cast this object as a GenericEntryVO as I am using AMFPHP to communicate serialize data with a Flex client.

I've read a few different ways to create constructors in PHP but the typical 'public function Foo()' for a class Foo was recommended for PHP 5.4.4

//in my EntryService.php class
public function getEntryByID($id)
{
    $link = mysqli_connect("localhost", "root", "root", "BabyTrackingAppDB");

    if (mysqli_connect_errno())
    {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    $query = "SELECT * FROM Entries WHERE id = '$id' LIMIT 1";

    if ($result = mysqli_query($link, $query))
    {
        // $entry = new GenericEntryVO(); this is where the problem lies!

        while ($row = mysqli_fetch_row($result))
        {
            $entry->id = $row[0];
            $entry->entryType = $row[1];
            $entry->title = $row[2];
            $entry->description = $row[3];
            $entry->value = $row[4];
            $entry->created = $row[5];
            $entry->updated = $row[6];
        }
    }

    mysqli_free_result($result);
    mysqli_close($link);

    return $entry;
}

//my GenericEntryVO.php class 
<?php

class GenericEntryVO
{
    public function __construct()
    {
    }

    public $id; 
    public $title;
    public $entryType;
    public $description;
    public $value;


    public $created;
    public $updated;

    // public $properties;
}

?>
هل كانت مفيدة؟

المحلول

Thanks again for the lead @eis. I didn't realize that you could access an error log in PHP. Being an as3/Flex developer, I am used to using a debugger with breakpoints. Not sure if PHP dev'rs have a similar IDE like Flash Builder.

After seeing that the generic 500 error was an issue with finding the right class to instantiate I did some investigating on my own. I needed to put require_once realpath(dirname(FILE).'/vo/GenericEntryVO.php'); at the top of the class. I was using as3 syntax and expecting the file path to be relative to the current file being processed. Here is where I found this solution:

How do I format a PHP include() absolute (rather than relative) path? It's about the 4th or 5th comment down by a person named @Zoredache

I am not sure if this is the best solution, but it has me up and running again with my data objects getting serialized for consumption in Flex.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top