3

In my entity, i've got a field with underscore in variable name, like this:

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $value_text;

And, for example, a get function:

public function getValueText()
{
    return $this->value_dec;
}

With that, symfony is throwing an exception:

Neither the property "value_text" nor one of the methods "value_text()", "getvalue_text()"/"isvalue_text()" or "__call()" exist and have public access in class "AppBundle\Entity\MyEntity".

So I've changed the function name, added the underscore, but then when i want to add a row, symfony is throwing same error, but in the other way - it's ignoring the underscore, and looking for function like getValueText().

Why that's happening? I've made two functions doing same thing, my code works, but ofcourse i think there is a better way to do this, without doubling the function.

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Rallyholic
  • 317
  • 1
  • 3
  • 21
  • 2
    Better using camelCase for variable name https://symfony.com/doc/current/contributing/code/standards.html#naming-conventions – hous Jan 04 '18 at 10:05

2 Answers2

1

Try to use this:

public function getValue_dec() {
    return $this->value_dec;
}

But the convention is to use camel case so It's better this:

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $valueDec;

public function getValueDec()
{
    return $this->valueDec;
}
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
0

Symfony uses camelCase for property naming conventions.

Here is official doc for Naming Conventions

Read more related articles

[PropertyInfo] Implement Naming Strategy for Properties

Added support for non-camel-case variable code conventions #29

habibun
  • 1,552
  • 2
  • 14
  • 29