At the Public API documentation, at the:
at the subsection "Displaying values from a Content", on the code, at the part inside the "foreach":
$valueHash = $fieldType->toHash( $field->value );
I believe the $field->value part should be corrected to $field only, since the $field variable is already assigned a value variable type from the line above:
$field = $content->getFieldValue( $fieldDefinition->identifier );
Trying to fetch a value variable type parameter from what already seems to be a value variable type doesn't make sense to me.
Found out while trying to base my code for a controller on this.