views:

51

answers:

1

I am working through the doctrine 2 (Beta3) sandbox and trying to apply the Zend Framework coding convention of placing a leading underscore to private class members. When I query Address, while its private members are NOT underscored, i retrieve the object as expected. When I add the underscores, regenerate and repopulate the db, and then run the same query I get the following error messages:

PHP Notice: Undefined index: id in ... Doctrine/ORM/Internal/Hydration/AbstractHydrator.php on line 184 PHP Fatal error: Uncaught exception 'Doctrine\DBAL\DBALException' with message 'Unknown column type requested.' in ... Doctrine/DBAL/DBALException.php:81

The DQL query:

$q = $em->createQuery('select u from Entities\Address u where u.id = ?1');
$q->setParameter(1, '1');
$address = $q->getSingleResult();

The ZFed Address class:

<?php

namespace Entities;

/** @Entity @Table(name="addresses") */
class Address
{
    /**
     * @Id @Column(type="integer", length=11, name="id")
     * @GeneratedValue(strategy="AUTO")
     */
    private $_id;

    /** @Column(type="string", length=255, name="street") */
    private $_street;

    public function getId()
    {
        return $this->_id;
    }

    public function getStreet()
    {
        return $this->_street;
    }

    public function setStreet($street)
    {
        $this->_street = $street;
    }

}
+1  A: 

You would have to write _ in front of all your DQL Queries yes.

Underscores in front of variables are some kind hungarian notation, which we as Doctrine team don't like. Even Zend Framework will drop that style for new code as far as i understood. Many other projects did the same and PEAR2 even changed their standard in this regard.

beberlei
Poll: Should underscore prefixing of non-public elements be dropped?http://zend-framework-community.634137.n4.nabble.com/Poll-Should-underscore-prefixing-of-non-public-elements-be-dropped-td2322936.html#noneThe Poll:https://spreadsheets.google.com/viewform?formkey=dEZOTGpMdjhzZDlmZGNMZVF0WnFTV2c6MQPS: Trust beberlei, he is Doctrine2 Core-Dev ;)
Benjamin Cremer
Ah good to know - goodbye underscores. Can I point you to my next question please: http://stackoverflow.com/questions/3624206/require-once-missing-doctrine-zend-framework
waigani
The thing I wonder though, is that most of Doctrine's code is written with underscores that prefix the class attributes. I use underscores for private/protected class attributes as well, would there be a chance for a support on underscored class attributes within entities?
Steven Rosato