Location: PHPKode > projects > phc > test/subjects/parsing/instring.php
<?php
	define("sc", 0);
	
	class X
	{
		var $y;

		function X()
		{
			$this->y = 123;
		}
	}

	$b = 1;
	$arr[0] = "foo";
	$arr["sc"] = "boo";
	$str = "bar";
	$x = new X();
	
	/*
	 * Simple syntax
	 *
	 * This might actually turn out to be more difficult to parse than
	 * "complex" syntax (which is standard syntax enclosed in {..}, where
	 * the first "{" must be followed by a "$".
	 *
	 * Possible variables:
	 *   "$a"     a an ident
	 *   "${a}"   a an ident
	 *   "$a->b"  a, b an ident
	 *   "$a[b]"  b an integer
	 *   "$a[b]"  b an ident (interpreted as a string)
	 */

	echo "a $bc\n";
	echo "a ${b}c\n";
	echo "a $arr[0] c\n";
	echo "a $arr[sc] c\n"; 		// "a " . $b["x"] . " c\n"; prints "boo"
	echo "a $str{0} c\n"; 		// Curlies are not interpreted
	echo "a $arr[0]{1} c\n";	// (Again)
	echo "a $x->y c\n";

	echo <<<END
a $bc d
END;
	echo <<<END
a ${b}c d
END;
	echo <<<END
a $b[0] d
END;
	echo <<<END
a $b[c] d
END;
	echo <<<END
a $b->c d
END;

	/* 
	 * Complex syntax 
	 */

	echo "a {$b} c\n";
	echo "a {$arr[0]} c\n";
	echo "a {$arr[sc]} c\n"; 		// Note: prints "foo"		
	echo "a {$str{0}} c\n"; 		// Curlies _are_ interpreted
	echo "a {$arr[0]{1}} c\n";
	echo "a {$arr["sc"]} c\n";		// while this prints "boo" 
	echo "a {$x->y} c\n";

	echo <<<END
a {$b} c
END;
	echo <<<END
a {$arr[0]} c
END;
	echo <<<END
a {$arr[sc]} c
END;
	echo <<<END
a {$arr{0}} c
END;
	echo <<<END
a {$arr[0]{1}} c
END;
	echo <<<END
a {$arr["sc"]} c
END;
	echo <<<END
a {$x->y} c
END;


	/*
	 * PHP will bark on this, but we don't
	 */
	
	echo "a $b[ 0 ] c\n";			// We don't generate an error
?>
Return current item: phc