PHP/Symfony2-在对象上打印

PHP/Symfony2-在对象上打印,php,ajax,symfony,Php,Ajax,Symfony,我有一些奇怪的事情正在发生,我想知道它们是否与PHP或Symfony有关。基本上,从我的表单发出ajax请求,表单数据发布到我的控制器 现在我需要对刚刚被持久化到数据库中的实体做一些工作,所以为了将它放到需要的地方,我有一个EventListener,我做了 protected $alertEntity; public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity();

我有一些奇怪的事情正在发生,我想知道它们是否与PHP或Symfony有关。基本上,从我的表单发出ajax请求,表单数据发布到我的控制器

现在我需要对刚刚被持久化到数据库中的实体做一些工作,所以为了将它放到需要的地方,我有一个EventListener,我做了

protected  $alertEntity;

public function postPersist(LifecycleEventArgs $args)
{
    $entity = $args->getEntity();
    if ($entity instanceof AvailabilityAlert) {
        $this->alertEntity = $entity;
    }
}

public function postFlush(PostFlushEventArgs $args)
{
    $this->api_service->addFlightsAction($this->alertEntity);
}
因此,我在postPersist中获取实体,然后在postFlush中将其传递到需要的位置

这一切都很好,这里没有问题。奇怪的是

public function addFlightsAction($alert){
    print_r($alert);
}
如果我将上述内容打印出来,它将永远持续下去,直到最终导致错误分配大小溢出

如果我在var_转储中执行上述操作,它会为我打印警报,但格式不可读,例如(简短摘录)


对象(Ontro\AlertBundle\Entity\AvailabilityAlert)[284]
私有“id”=int 39
私有“searchCommand”=字符串“A20APRLONLAX”(长度=12)
私有“断开连接”=字符串“否”(长度=2)
私人“最新更新”=
对象(日期时间)[288]
公共“日期”=字符串“2015-02-19 10:54:54”(长度=19)
公共“时区类型”=整数3
公共“时区”=字符串“欧洲/伦敦”(长度=13)
私有“isDeleted”=int 0
私有“alertStatus”=字符串“活动”(长度=6)
私人“预订类”=
对象(条令\ORM\PersistentCollection)[372]
专用“快照”=
那么它为什么要这样做呢?有没有办法把它打印出来以便我能看到?我不介意上面的输出,只要它去掉了所有的html标记


谢谢

您已经安装了xdebug,它的格式为
var\u dump
。或者按照说明禁用它,但仍然会出现与
print\r
相同的问题,并出现分配错误

如果您想保留xdebug(我想您应该这样做),您有两个选择,或者在php.ini中禁用
xdebug.重载\u var\u dump
(),或者您可以使用
\doctor\Common\Util\Debug::dump($alert)


在symfony2.6中,他们引入了一个新特性,这是一个内置的非常强大的调试工具。您可以在此处查看文档:

您已经安装了xdebug,其格式为
var\u dump
。或者按照说明禁用它,但仍然会出现与
print\r
相同的问题,并出现分配错误

如果您想保留xdebug(我想您应该这样做),您有两个选择,或者在php.ini中禁用
xdebug.重载\u var\u dump
(),或者您可以使用
\doctor\Common\Util\Debug::dump($alert)


在symfony2.6中,他们引入了一个新特性,这是一个内置的非常强大的调试工具。您可以在此处查看文档:

此外,请尝试Vardumpper组件及其提供的dump()函数:可以将其包含在您的答案中。这样会更容易找到。此外,请尝试VarDumper组件及其提供的dump()函数:可以将其包含在您的答案中。这样更容易找到。
<pre class='xdebug-var-dump' dir='ltr'>
<b>object</b>(<i>Ontro\AlertBundle\Entity\AvailabilityAlert</i>)[<i>284</i>]
  <i>private</i> 'id' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>39</font>
  <i>private</i> 'searchCommand' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'A20APRLONLAX'</font> <i>(length=12)</i>
  <i>private</i> 'isConnecting' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'no'</font> <i>(length=2)</i>
  <i>private</i> 'lastUpdated' <font color='#888a85'>=&gt;</font> 
    <b>object</b>(<i>DateTime</i>)[<i>288</i>]
      <i>public</i> 'date' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2015-02-19 10:54:54'</font> <i>(length=19)</i>
      <i>public</i> 'timezone_type' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>3</font>
      <i>public</i> 'timezone' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Europe/London'</font> <i>(length=13)</i>
  <i>private</i> 'isDeleted' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>0</font>
  <i>private</i> 'alertStatus' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Active'</font> <i>(length=6)</i>
  <i>private</i> 'bookingClass' <font color='#888a85'>=&gt;</font> 
    <b>object</b>(<i>Doctrine\ORM\PersistentCollection</i>)[<i>372</i>]
      <i>private</i> 'snapshot' <font color='#888a85'>=&gt;</font>