z7zmey / php-parser

PHP parser written in Go

Home Page:https://php-parser.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pretty printer does not print when syntax error is found.

truestblue opened this issue · comments

commented

This is php code taken from php-src:

INPUT:

 interface Serializable
{

	function serialize();
	function unserialize($serialized);
}

class ArrayObject implements IteratorAggregate, ArrayAccess, Countable
{
	
	const STD_PROP_LIST     = 0x00000001;
	const ARRAY_AS_PROPS    = 0x00000002;


	function __construct($array, $flags = 0, $iterator_class = "ArrayIterator") {/**/}

	function uasort(mixed cmp_function) {/**/}

	/** Sort the entries by key using user defined function.
	 */
	function uksort(mixed cmp_function) {/**/}

}?>

OUTPUT:

syntax error: unexpected T_STRING, expecting T_VARIABLE at line 20
syntax error: unexpected T_STRING, expecting T_VARIABLE at line 24

File Out:
<?php
interface Serializable
{
	function serialize();
	function unserialize($serialized);
}
{

}
{
};?>

This behavior expected for syntax-invalid files - AST for the invalid part is lost.
I suppose that file is using for documentation only.