PHP-und Symfony-Objekt array-Konvertierung von type cast

Bin ich mit symfony2 und wie CreateForm im um die http post-Daten. Nach Hexe ich:

$Data = (array) $form->getData();

Und ich bekomme:

array (size=1)
  '�Far\MT\AccountBundle\Entity\Movement�toAccount' => int 3

Ich glaube nicht, das ist das normale Verhalten für diese Fälle, alle Anregungen?

den toAccount sollte der vollständige name des Indexes.

War nicht in der Lage zu reproduzieren die Bedingungen in einem test-Fall für die cli:

<?php

namespace A;

class MyClass
{
    public $id;
    public $name;
    public $age;
}

$object = new MyClass();
$object->name = "Andre";
$object->id   = 1;
$object->age  = 30;

var_dump($object);

$Ar = (array) $object;
var_dump($Ar)

Diese oben gearbeitet, ok.

Habe ich diese Lösung:

//comment
$Data = $form->getData();
$obj = new \ReflectionObject($Data);
$props = $obj->getProperties();

$propname = array();
foreach ($props as $prop) {

    $tmp = "get".ucfirst($prop->name);

    if (($res = $Data->$tmp() )!== null) {
        $propname[$prop->name] = $res;
    }
}
$tmpSearch = $propname;

Werde ich es sauber nach.

Schreibe einen Kommentar