DDC-1211: Expr::literal problem with numeric value 0 #1818

doctrinebot opened this Issue Jun 16, 2011 · 3 comments

2 participants


Jira issue originally created by user comfortablynumb:


I'm using master branch of Doctrine 2. Including an Expr with a numeric 0 value (not a string):

$value = 0;

$qb->expr()->gte($field, $qb->expr()->literal($value));

Expr::literal method will return an empty string ('') instead of '0', which causes that this expression be something like:

entity.myField >=  

instead of:

entity.miField >= '0''

This makes the query fail. Tracking the issue down I've found this on Expr\Base::add method:

    public function add($arg)
         if ( ! empty($arg) || ($arg instanceof self && $arg->count() > 0)) {
            // If we decide to keep Expr\Base instances, we can use this check
            if ( ! is_string($arg)) {
                $class = get_class($arg);

                if ( ! in*array($class, $this->*allowedClasses)) {
                    throw new \InvalidArgumentException("Expression of type '$class' not allowed in this context.");

            $this->_parts[] = $arg;

The problem is that empty function returns true if you pass '0', so a call to Expr\Base::add would end on NOT adding '0' to $this->_parts array. That's why it finally returns ''.

I wanted to make the fix for this but I'm having issues running the phing build task. Which are the steps to follow to run the tests? Running phing build task I get on the "test" task:

Could not create task/type: 'nativephpunit'. Make sure that this class has been declared using taskdef / typedef.



Comment created by @beberlei:

Assigned to guilherme, i suppose we could change the !empty($arg) to $arg !== null ?


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0.7 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment