0)) { throw new \InvalidArgumentException("Parameter 'id' must be a positive integer."); } $reflClass = new \ReflectionClass($object); if(!$reflClass->hasProperty('id')) { throw new \InvalidArgumentException("Object has no property 'id'."); } $idProp = $reflClass->getProperty('id'); $idProp->setAccessible(true); $idProp->setValue($object,$id); } }