{"id":21689,"library":"phply","title":"phply","description":"A lexer and parser for PHP source code implemented using PLY (Python Lex-Yacc). Provides a tokenizer, parser, and AST representation for PHP. Current version 1.2.6, release cadence is sporadic.","status":"active","version":"1.2.6","language":"python","source_language":"en","source_url":"https://github.com/viraptor/phply","tags":["php","lexer","parser","ast","ply"],"install":[{"cmd":"pip install phply","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"note":"The AST module is phpast, not phply.ast or phply.phpast as a top-level import.","wrong":"","symbol":"phply.phpast","correct":"from phply import phpast"},{"note":"The lexer module is named phplex, not lexer.","wrong":"from phply import lexer","symbol":"phply.lexer","correct":"from phply import phplex"},{"note":"The parser module is named phpparse, not parser.","wrong":"from phply import parser","symbol":"phply.parser","correct":"from phply import phpparse"}],"quickstart":{"code":"from phply import phplex, phpparse\nfrom phply import phpast as ast\ncode = '<?php echo \"Hello, World!\"; ?>'\ntokens = list(phplex.lex(code))\nprint('Tokens:', tokens)\nparser = phpparse.make_parser()\nparsetree = parser.parse(code, lexer=phplex.lexer)\nprint('AST:', parsetree)","lang":"python","description":"Basic usage: tokenize and parse a PHP snippet."},"warnings":[{"fix":"Use 'from phply import phplex'.","message":"The lexer module is called 'phplex' not 'lexer'. Importing 'from phply import lexer' will fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'from phply import phpparse'.","message":"The parser module is called 'phpparse' not 'parser'. Importing 'from phply import parser' will fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'parser = phpparse.make_parser()' then 'parser.parse(code, lexer=phplex.lexer)'.","message":"The 'make_parser()' function returns a LALR(1) parser. In some versions, parsing with case sensitivity may differ. Always pass a lexer to parse() to avoid confusion.","severity":"deprecated","affected_versions":">=1.2"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install ply'.","cause":"PLY is a required dependency but not automatically installed.","error":"ModuleNotFoundError: No module named 'ply'"},{"fix":"Use 'from phply import phplex' instead.","cause":"Incorrect import path; lexer is actually in 'phplex'.","error":"ImportError: cannot import name 'lexer' from 'phply'"},{"fix":"Use 'from phply import phpast'.","cause":"Trying 'import phply' then 'phply.phpast', but phpast is a submodule.","error":"AttributeError: module 'phply' has no attribute 'phpast'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}