Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 创建新实例失败_Php_Oop_Serialization_Constructor_Amfphp - Fatal编程技术网

Php 创建新实例失败

Php 创建新实例失败,php,oop,serialization,constructor,amfphp,Php,Oop,Serialization,Constructor,Amfphp,我对PHP比较陌生,取得了一些不错的成功,但我遇到了以下问题: 如果我尝试创建GenericEntryVO类的一个新实例,我会得到一个500错误,几乎没有有用的错误信息。但是,如果使用泛型对象作为结果,则不会出现错误。我希望能够将此对象转换为GenericEntryVO,因为我正在使用AMFPHP与Flex客户端通信序列化数据 我已经阅读了一些在PHP中创建构造函数的不同方法,但是PHP5.4.4推荐使用Foo类的典型“public function Foo()” //in my EntrySe

我对PHP比较陌生,取得了一些不错的成功,但我遇到了以下问题:

如果我尝试创建GenericEntryVO类的一个新实例,我会得到一个500错误,几乎没有有用的错误信息。但是,如果使用泛型对象作为结果,则不会出现错误。我希望能够将此对象转换为GenericEntryVO,因为我正在使用AMFPHP与Flex客户端通信序列化数据

我已经阅读了一些在PHP中创建构造函数的不同方法,但是PHP5.4.4推荐使用Foo类的典型“public function Foo()”

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

?>
//在my EntryService.php类中
公共函数getEntryByID($id)
{
$link=mysqli_connect(“localhost”、“root”、“root”、“BabyTrackingAppDB”);
if(mysqli\u connect\u errno())
{
printf(“连接失败:%s\n”,mysqli_Connect_error());
退出();
}
$query=“从id='$id'限制1'的条目中选择*;
如果($result=mysqli_query($link,$query))
{
//$entry=new GenericEntryVO();这就是问题所在!
while($row=mysqli\u fetch\u 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_免费_结果($result);
mysqli_close($link);
返回$entry;
}
//我的GenericEntryVO.php类

再次感谢@eis的领导。我没有意识到您可以在PHP中访问错误日志。作为一名as3/Flex开发人员,我习惯于使用带有断点的调试器。不确定PHP开发人员是否有类似于Flash Builder的IDE

在发现泛型500错误是寻找正确的类进行实例化的问题之后,我自己做了一些调查。我需要放置require_once realpath(dirname(FILE)。/vo/GenericEntryVO.php');在班上名列前茅。我使用的是as3语法,希望文件路径与当前正在处理的文件相对。我在这里找到了这个解决方案:

这是一个叫@Zoredache的人写的第四或第五条评论


我不确定这是否是最好的解决方案,但它让我重新启动并运行,我的数据对象在Flex中被序列化以供使用。

请启用错误日志记录/读取错误日志以获取“错误500”背后的真实错误消息。这应该会引导你前进。你能分享这个
几乎没有有用的错误信息吗?@eis它看起来很难找到GenericEntryVO.php文件吗?这很奇怪,因为我的services.php文件中的其他方法使用GenericEntryVO类没有任何问题。我也会粘贴它。由于字符数最多,无法在此发布代码,但以下是pastebin链接:错误日志:整个服务类:对于调试,请查看xdebug以及如何将其与您喜爱的IDEOOOH集成。谢谢@fd8s0。他们为Eclipse提供了大量在线安装资源。
realpath()
不是必需的。如果您使用的是PHP5.3,那么您的示例将变得非常简单,如
include_once\u_DIR__./vo/GenericEntryVO.php'