NewYour coding agent can read the release notes before it upgrades.Set up the MCP server β
Packagist, #304 most downloaded on Packagist
π Nette PHP Generator: generates PHP code from objects. Classes, enums, functions and whole files, with namespaces resolved for you, and always up to date with the latest PHP.
Latest stable
v4.2.4
Last release 26 days ago
26 Oct 2026
Ships fairly regularly
a new release about every 3 months
Nearly every release is documented
notes for 56 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
80 releases Β· first in 2014
Drag across the ruler to compare, or tap a release to open it.
fromCode() now keeps a file comment placed before declare(strict_types=1)
fromCode() now keeps a file comment placed before declare(strict_types=1) (#182)PropertyHookType is now an alias of PropertyAccessMode, so both enums are interchangeable wherever hooks are added or looked upfinal private constant, an abstract final property hook, and an enum whose backing type is not int or string or whose case values do not match itsetHooks() validates hook types, and the presence of php-parser 5 is detected reliably, with a clear message when an older version is installedLoading a class with ClassType::from() or fromCode() now keeps the types of typed class constants (PHP 8.3)
ClassType::from() or fromCode() now keeps the types of typed class constants (PHP 8.3)Your coding agent can read these notes before it upgrades. Set up the MCP server β
The `$namespace` parameter in ClassLike constructors is deprecated. Use setNamespace() instead. The old signature still works for now, but will be remβ¦
This release focuses on making namespaces and classes work together more naturally. Classes now know which namespace they belong to, constructors accept fully qualified names, and a new unified add() method on PhpFile ties it all together. Under the hood, the Factory got a thorough refactoring and the codebase passed its first mandatory static analysis check.
PhpNamespace::add() now automatically assigns itself as the namespace of any ClassLike passed to it. If your code relied on getNamespace() returning null after adding a class to a namespace, you'll need to update that assumption.
PhpFile::add() β a single entry point for adding classes, interfaces, traits, enums, functions, and namespaces to a file. It handles namespace creation and bracket syntax automatically, so you can build a complete file with just add() calls.
ClassLike::getFullName() β returns the fully qualified name when the class belongs to a namespace (e.g., App\Model\User), the short name otherwise, or null for anonymous classes.
ClassLike constructors now accept FQN β pass 'App\Model\User' and the namespace is extracted automatically. No need to create the namespace separately for simple cases.
PhpNamespace::add() accepts GlobalFunction β the unified add() method now handles functions alongside class-like types, making the namespace API more consistent.
The $namespace parameter in ClassLike constructors is deprecated. Use setNamespace() instead. The old signature still works for now, but will be removed in a future version.
Nothing published for this version
addTrait() second argument is deprecated (BC break)
OAuth 2.0 authentication for Gmail and Microsoft, one-click unsubscribe headers, Ed25519 DKIM signing, a real CSS cascade for inlining, and a security patch that alone makes updating worth it. Fully backward compatible.
David Grudl
4 months ago
final promoted property in PHP 8.5
Factory::fromClassReflection() extracts property hook bodies
Factory::fromClassReflection() extracts property hook bodies (#172)Factory::fromClassReflection() rejects $withBodies for interfacesadded support for PHP 8.4 features
ClassManipulator::implement() can implement abstract classesClassManipulator::implementInterface() renamed to implement()Parameter & Property: isNullable() returns true when default value is null (possible BC break)
isNullable() returns true when default value is null (possible BC break)added PhpNamespace::getClass() & getFunction()
PhpNamespace::getClass() & getFunction()CommentAware::removeComment()PhpFile::removeNamespace()from() accepts first-class callablesPsrPrinter: opening bracket on the correct line #155
ClassLike::from return type assert the subclass type (BC break) (#154)Dumper::dumpArray(), dumpArguments() optimizationaddMember(), addMethod(), addProperty(), addConstant(), addCase() #152Extractor: supports PHP-Parser 5.0
dumpCustomObject()printFile() [Close #147]Support union type in Type::nullable
ClassType: getType() is deprecated
inheritMethod() & inheritProperty()ConstantsAware::getConstant()Extractor::extractAll() extracts only top-level classes and functions, fixed file comment parsinggetType() is deprecatedClassType::class(), interface(), traits() & enum() are deprecated
Extractor::extractAll() fixed file comment parsing
Extractor::extractAll() fixed file comment parsing- Parameters can have comments - added Literal::new() #130 - fixed #135
Literal::new() #130Factory: properties in readonly classes are not readonly
getParameter() & hasParameter()hasConstant() (#133)Printer: added $singleParameterOnOneLine
added support for typed constants
added support for PHP 8.2 features: DNF types, constants in traits, readonly classes, Type::True
Helpers::formatDocComment() added option $forceMultiLineDumper::dumpObject() refactoring
Printer: added $bracesOnNextLine #112
__serialize()Helpers::formatDocComment(), Printer::printFunction() & etc normalizes whitespaceClassType divided into InterfaceType, TraitType & EnumType
removeUse() #102ClassType::__clone() clones traitsdeprecated magic properties (BC break)
This release takes advantage of all the new features of PHP 8 and cleans up some issues in the API.
Stricter behaviour:
Changes:
$thisDeprecations:
ClassType::withBodiesFrom() replaced with from(..., withBodies: true)GlobalFunction::withBodyFrom() replaced with from(..., withBody: true)Extractor: keeps the first comment in the method #119
Extractor: added support for Readonly promoted parameters
Extractor: supports promoted parameters #103
removeUse() #102ClassType::__clone() clones traitsExtractor: preserves the first comment in the file #100
removeClass() & removeFunction()This is the last 3.6.x release.
PhpNamespace: added resolveName()
resolveName()PhpNamespace::addUse() ignores names in current namespace #96BLOG POST: https://blog.nette.org/en/phpgenerator-3-6-news-from-php-8-1-and-more
use-statements for functions & constants
addUse() & simplifyName() is case-insensitivePhpNamespace::simplifyName() fixed collision when alias already existsPhpNamespace::addUse() removed parameter $aliasOut (BC break)PhpNamespace::addUse() simplified aliases generationPrinter: added property $wrapLength #55 #56
getType(), getReturnType(): added option $asObject that returns Nette\Utils\TypePhpNamespace::simplifyType() supports generics like Foo<A, B>PhpNamespace::unresolveName() renamed to simplifyName()Helpers::unindent() fixed when level = 0Dumper::format() placeholder ? must not be followed by \wPhpNamespace::addUse() added validationadded ClassType::fromCode() & PhpFile::fromCode() #79
ClassType::fromCode() & PhpFile::fromCode() #79getClasses()added support for intersection types foo&bar
Dumper: dumps Closure as PHP code
fn() without spaceBranch 3.5 is no longer supported
Printer: parameter wrapping counts with function name length [Closes #77]
Printer: fixed combination nullable + mixed #74
setValue() automatically turns on initialized state #71For the details you can have a look at the diff.
Nothing published for this version
Supports all new PHP 8 features!
Supports all new PHP 8 features!
BLOG POST https://blog.nette.org/en/news-in-phpgenerator-3-5
PHP-safe indentation replaced with Helpers::unindent() because requires too much memory
unindent() because requires too much memoryextractBody() replaces multi-line & HEREDOC strings with single-lineThis is the last 3.4.x release.
Factory: reads class constants with visibility & phpDoc
ClassType: added removeImplement() & removeTrait() #53
removeImplement() & removeTrait() #53printParameters() is publicprintType()fromCallable()getType()This is the last 3.3.x release.
ClassType: added new setter/getters for each type
dumpArray() hides keys only in non-associative arrays #51For the details you can have a look at the diff.
Nothing published for this version
Nothing published for this version
added support for PHP 7.4 typed properties
Nette Forms 3.3 adds {form detached} to nest one form inside another. We explain the form attribute trick, the new {form scope} tag and the link to POST links.
David Grudl
5 months ago
PsrPrinter: fixed indentation of dumps #41
printUses()hasProperty() & hasMethod()This is the last 3.2.x release.
Printer::setTypeResolving() adds ability to print uresolved code #31
setTypeResolving() adds ability to print uresolved code #31format() is preferred over formatArgs() because we have variadics :)For the details you can have a look at the diff.
Printer: fixed use statements generation
addUse() #38For the details you can have a look at the diff.
ClassType::getNamespace() is softly deprecated. An object can be in multiple namespaces.
New features
Printer, code from __toString moved to PrinterPsrPrinter, compatible with PSR-2 and PSR-12 [Closes #30]PhpNamespace::add() [Closes #27]NameAware::cloneWithName()FunctionLike::removeParameter() & ClassType::removeMethod(), removeProperty(), removeConstant()ClassType::addMember() [Closes #35]VISIBILITY_* constantsChanges
PhpNamespace::add*() - removed checking whether class already exists - to be consistent with the rest of package (BC break)ClassType::getNamespace() is softly deprecated. An object can be in multiple namespaces.For the details you can have a look at the diff.
Printer: fixed use statements generation
This is the last v3.1.x release.
ClassType::from() resolves inheriting interfaces #32
from() resolves inheriting interfaces #32getNamespaces()For the details you can have a look at the diff.
Closure: chops 'uses' when are longer than WRAP_LENGTH
tabsToSpaces()For the details you can have a look at the diff.
phpDoc: added $var name to @param
For the details you can have a look at the diff.
Parameter::setOptional() triggers deprecation notice
This is the last v3.0.x release.
This is the last v3.0.x release.
from() resolves inheriting interfaces #32For the details you can have a look at the diff.
Closure: chops 'uses' when are longer than WRAP_LENGTH
tabsToSpaces()For the details you can have a look at the diff.
phpDoc: added $var name to @param
For the details you can have a look at the diff.
PhpNamespace: added support for PHP 7.2 type 'object'
For the details you can have a look at the diff.
added support for class constants
For the details you can have a look at the diff.
One column per quarter.