3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class tokenstream { // Входной поток private $input_stream; // Указатель позиции во входном потоке public $seek = 0; // Конструктор public function __construct ( $input ) { // Инициализируем входной поток $this -> input_stream = $input; } // Возвращает очередной символ из входного потока public function readChar ( ) { $char = ( isset ( $this -> input_stream [ $this -> seek ] ) ? $this -> input_stream [ $this -> seek ] : false ); $this -> seek++; return $char; } // Производит токенизацию public function tokenize ( ) { $output = array ( ); while ( ( $char = $this -> readChar ( ) ) !== false ) { if ( preg_match ( '/\s/', $char ) ) { // Неотображаемые символы } elseif ( preg_match ( '/\"/', $char ) ) { // Кавычки $output [ ] = 'T_QUOTE'; } elseif ( условие ) { $output [ ] = 'T_...'; } } return $output; } } // Исходный код для разбора $my_source = ' function foo ( ) { $my_var = "foo-bar"; } '; // Создаем экземпляр класса парсера $tokenstream = new tokenstream ( $my_source ); // Парсим исходный код и распечатываем результат print_r ( $tokenstream -> tokenize ( ) );
Output for 5.0.2 - 7.1.0
Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Array ( [0] => T_... [1] => T_... [2] => T_... [3] => T_... [4] => T_... [5] => T_... [6] => T_... [7] => T_... [8] => T_... [9] => T_... [10] => T_... [11] => T_... [12] => T_... [13] => T_... [14] => T_... [15] => T_... [16] => T_... [17] => T_... [18] => T_... [19] => T_... [20] => T_... [21] => T_... [22] => T_QUOTE [23] => T_... [24] => T_... [25] => T_... [26] => T_... [27] => T_... [28] => T_... [29] => T_... [30] => T_QUOTE [31] => T_... [32] => T_... )
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Notice: Uninitialized string offset: 53 in /in/Z7n9p on line 14 Notice: Use of undefined constant условие - assumed 'условие' in /in/Z7n9p on line 25 Array ( [0] => T_... [1] => T_... [2] => T_... [3] => T_... [4] => T_... [5] => T_... [6] => T_... [7] => T_... [8] => T_... [9] => T_... [10] => T_... [11] => T_... [12] => T_... [13] => T_... [14] => T_... [15] => T_... [16] => T_... [17] => T_... [18] => T_... [19] => T_... [20] => T_... [21] => T_... [22] => T_QUOTE [23] => T_... [24] => T_... [25] => T_... [26] => T_... [27] => T_... [28] => T_... [29] => T_... [30] => T_QUOTE [31] => T_... [32] => T_... [33] => T_... )
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Z7n9p on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Z7n9p on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/Z7n9p on line 4
Process exited with code 255.