0

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;
}

?>
Charles
  • 50,943
  • 13
  • 104
  • 142
jusopi
  • 6,791
  • 2
  • 33
  • 44
  • 3
    please enable error logging / read the error log to get the real error message behind the "error 500". That should guide you forward. – eis Nov 12 '12 at 23:01
  • Can you please share this `little to no helpful error information`? – dev-null-dweller Nov 12 '12 at 23:13
  • @eis it looks like it's having a hard time finding the GenericEntryVO.php file? That's odd because other methods I have in my services.php file make use of the GenericEntryVO class with no issue. I will paste it as well. couldn't post the code here because of max characters but here are pastebin links: error log: [link](http://pastie.org/5371978) entire services class: [link](http://pastie.org/5371989) – jusopi Nov 13 '12 at 15:06

1 Answers1

0

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.

Community
  • 1
  • 1
jusopi
  • 6,791
  • 2
  • 33
  • 44
  • 1
    for debugging, take a look at xdebug and how to integrate it with your favorite IDE – fd8s0 Nov 13 '12 at 15:26
  • ooooh, will do thanks @fd8s0. They make it for Eclipse with plenty of resources online on installation. – jusopi Nov 13 '12 at 15:58
  • 1
    `realpath()` is not necessary. if you're on php 5.3, your example gets as easy as `include_once __DIR__./vo/GenericEntryVO.php';`. – glasz Nov 13 '12 at 16:06