PhpParser\Error::getStartColumn PHP Method

getStartColumn() public method

Gets the start column (1-based) into the line where the error started.
public getStartColumn ( string $code ) : integer
$code string Source code of the file
return integer
    public function getStartColumn($code)
    {
        if (!$this->hasColumnInfo()) {
            throw new \RuntimeException('Error does not have column information');
        }
        return $this->toColumn($code, $this->attributes['startFilePos']);
    }

Usage Example

 private function formatErrorMessage(Error $e, $code)
 {
     if ($e->hasColumnInfo()) {
         return $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code) . ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code);
     } else {
         return $e->getMessage();
     }
 }