ylliX - Online Advertising Network

Expected argument of type “string”, “NULL” given when using form in Symfony 4.1

Expected argument of type “string”, “NULL” given is very common question and seems to not be handled since Symfony 2

So if you are using forms and got such error after submit – digging to find what is causing can be very annoying. The easiest solution is to find file:

and in function:
public function setValue(&$objectOrArray, $propertyPath, $value)

almost at end, just before:
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0);

just add:

echo '<pre>';
echo '</pre>';

This will cause to print all required data to find which field is causing issue. The most important is $propertyPath variable which will give you name of field:

object(stdClass)#4165 (5) {
  string(45) "Symfony\Component\PropertyAccess\PropertyPath"
  array(1) {
    string(8) "csvField"
  array(1) {
  string(8) "csvField"

At given example fieldname is “csvField”.

Leave a Reply