Less.php
A pure-PHP port of the Less.js CSS preprocessor that compiles LESS into CSS.
Repository Health
Technical Analysis
Less.php is a PHP implementation of the LESS CSS preprocessor, porting the official Less.js compiler to run natively in PHP with no Node.js dependency. It parses LESS stylesheets — with variables, mixins, nesting, functions, and imports — and compiles them into standard CSS, mirroring the code structure of upstream Less.js to stay compatible (targeting Less.js 3.13.1).
Maintained by the Wikimedia Foundation and used in MediaWiki, the library exposes a Less_Parser API for programmatic compilation, a file-based cache, v3 source map generation, and a bundled lessc command-line tool with a watch mode. It is the de-facto choice for PHP projects that need server-side LESS compilation.
What You Get
- A
Less_ParserAPI for compiling LESS strings and files to CSS in PHP - Compatibility with Less.js 3.13.1 semantics (variables, mixins, nesting, functions, imports)
- A built-in file-based cache to skip recompilation of unchanged stylesheets
- v3 source map generation for debugging compiled CSS
- A bundled
lessccommand-line tool with a watch mode
Common Use Cases
- Compiling LESS themes to CSS server-side in PHP applications like MediaWiki
- Generating CSS at build or request time without a Node.js toolchain
- Producing source maps to map compiled CSS back to LESS sources during development
- Running command-line LESS compilation and watching for changes via lessc
Under The Hood
Architecture - The compiler lives under lib/Less/ and deliberately mirrors the class structure of upstream Less.js: a parser tokenizes LESS into an AST of node types (rules, mixins, selectors, expressions), which are then evaluated and rendered to CSS. The public entry point is Less_Parser, with lessc.inc.php providing a classmap shim and bin/lessc wrapping the parser as a CLI. Caching and source-map generation are layered on top of the core parse/compile flow.
Tech Stack - Pure PHP requiring PHP >=8.1, with PSR-0 autoloading for the Less namespace. Dev tooling is the MediaWiki stack: PHPUnit 10, mediawiki-codesniffer, phan static analysis, minus-x, and parallel-lint, all wired through Composer scripts.
Code Quality - Strong for a community port: a test/ suite with fixtures and a benchmark script, plus CI enforcing phpcs, phan, and lint. Mirroring Less.js structure keeps the port maintainable and makes upstream feature parity tractable. The main caveat, documented in the README/SECURITY, is that LESS input should be treated as trusted server-side code.
API Design - Getting started is a few lines — instantiate Less_Parser, call parseFile/parse, then getCss(). Options (cache dir, source maps, import paths) are passed as an array, matching Less.js conventions so developers coming from the JS ecosystem feel at home. The bundled lessc binary offers a familiar CLI with watch mode for non-programmatic use.
Used by 2 apps in this directory
matomo
Analytics
Open-source, privacy-first web and app analytics that puts you in complete control of your data.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.