Improve code to throw exception getting parents class instead of php warning

Related to https://github.com/doctrine/common/pull/274