note 130403 added to class.phptoken

From: Date: Thu, 03 Jul 2025 15:12:27 +0000
Subject: note 130403 added to class.phptoken
Groups: php.notes 
Request: Send a blank email to php-notes+get-222255@lists.php.net to get a copy of this message
80-line obfuscator which just strips spaces and comments and replaces variables, touching neither classes no functions, but making your code significantly less readable. <?php $source = file_get_contents(__FILE__); $tokens = PhpToken::tokenize($source); $num = count($tokens); $prev = new PhpToken(T_BAD_CHARACTER, ' '); $prev->prev = null; $current = null; $j = 0; $vars = []; $vi = 0; $body = ''; while ($j < $num) { $current = $tokens[$j]; switch ($current->id) { case T_WHITESPACE: case T_COMMENT: case T_DOC_COMMENT: goto next; case T_VARIABLE: goto variable; default: goto out; } variable: $id = substr($current->text, 1); if ($id === 'GLOBALS' || $id === '_SERVER' || $id === '_GET' || $id === '_POST' || $id === '_FILES' || $id === '_REQUEST'|| $id === '_SESSION' || $id === '_ENV' || $id === '_COOKIE' || $id === 'argc' || $id === 'argv' || $id === 'this') { goto out; } elseif ($prev->id === T_GLOBAL || $prev->id === T_STATIC || $prev->id === T_PUBLIC || $prev->id === T_PRIVATE || $prev->id === T_PROTECTED) { goto out; } elseif (!isset($vars[$id])) { $vars[$id] = '_' . dechex($vi++); } $current->text = "\${$vars[$id]}"; out: $first = $current->text[0]; $last = $prev->text[strlen($prev->text) - 1]; if (($last >= 'A' && $last <= 'Z' || $last >= 'a' && $last <= 'z' || $last >= '0' && $last <= '9' || $last == '_' ) && ($first >= 'A' && $first <= 'Z' || $first >= 'a' && $first <= 'z' || $first >= '0' && $first <= '9' || $first == '_' || $first == '\\')) { $body .= ' '; } $body .= $current->text; $current->prev = $prev; $prev = $current; next: $j++; } echo $body; ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 46.39.45.251) ---- Manual Page -- https://php.net/manual/en/class.phptoken.php Edit -- https://main.php.net/note/edit/130403 Del: integrated -- https://main.php.net/note/delete/130403/integrated Del: useless -- https://main.php.net/note/delete/130403/useless Del: bad code -- https://main.php.net/note/delete/130403/bad+code Del: spam -- https://main.php.net/note/delete/130403/spam Del: non-english -- https://main.php.net/note/delete/130403/non-english Del: in docs -- https://main.php.net/note/delete/130403/in+docs Del: other reasons-- https://main.php.net/note/delete/130403 Reject -- https://main.php.net/note/reject/130403 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222255) next »