1

I have some weird things going on and I was wondering whether they are PHP or Symfony related. Basically, from my form, an ajax request is made and the form data posted to my controller.

Now I need to do some work with the entity that has just been persisted to the database, so to get this to where it needs to go, I have an EventListener and I do

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

So I get the entity in postPersist, and then pass it to where it needs to go in the postFlush.

This is all fine, no problems here. The weird part is this

public function addFlightsAction($alert){
    print_r($alert);
}

If I have the above in a print_r, it goes on forever until it eventually gives the error allocation size overflow.

If I do the above in a var_dump, it prints out the alert for me, but its in an unreadable format e.g. (short extract)

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

So why would it be doing this? Is there any way I can print it out nicely so I can see it? I dont mind the above output as long as it got rid of all the html tags.

Thanks

Nick Price
  • 953
  • 2
  • 12
  • 26

1 Answers1

4

You've got xdebug install which formats var_dump for you. Either disable it following the instructions here but that'll still give you the same issue as print_r with the allocation error.

If you want keep xdebug (which I imagine you do, and should), you have two options, either disable xdebug.overload_var_dump (docs) in your php.ini or you can use \Doctrine\Common\Util\Debug::dump($alert) instead.

In Symfony 2.6 they have introduced a new feature, VarDumper which is a pretty powerful debugging tool built right in. You can check out the documentation here: http://symfony.com/doc/current/components/var_dumper/introduction.html

Community
  • 1
  • 1
Prisoner
  • 27,391
  • 11
  • 73
  • 102