tag:github.com,2008:https://github.com/nette/php-generator/releasesRelease notes from php-generator2026-02-26T00:59:06Ztag:github.com,2008:Repository/17694277/v4.2.22026-02-26T00:59:43ZReleased version 4.2.2<p>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 <code>add()</code> 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.</p>
<ul>
<li>
<p><strong>PhpNamespace::add()</strong> now automatically assigns itself as the namespace of any ClassLike passed to it. If your code relied on <code>getNamespace()</code> returning <code>null</code> after adding a class to a namespace, you'll need to update that assumption.</p>
</li>
<li>
<p><strong>PhpFile::add()</strong> – 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 <code>add()</code> calls.</p>
</li>
<li>
<p><strong>ClassLike::getFullName()</strong> – returns the fully qualified name when the class belongs to a namespace (e.g., <code>App\Model\User</code>), the short name otherwise, or <code>null</code> for anonymous classes.</p>
</li>
<li>
<p><strong>ClassLike constructors now accept FQN</strong> – pass <code>'App\Model\User'</code> and the namespace is extracted automatically. No need to create the namespace separately for simple cases.</p>
</li>
<li>
<p><strong>PhpNamespace::add() accepts GlobalFunction</strong> – the unified <code>add()</code> method now handles functions alongside class-like types, making the namespace API more consistent.</p>
</li>
<li>
<p>The <strong><code>$namespace</code> parameter in ClassLike constructors</strong> is deprecated. Use <code>setNamespace()</code> instead. The old signature still works for now, but will be removed in a future version.</p>
</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.2.12026-02-09T05:43:59Zv4.2.1<p>version 4.2.1</p>dgtag:github.com,2008:Repository/17694277/v4.2.02025-08-06T18:24:55ZReleased version 4.2.0<ul>
<li>requires PHP 8.1</li>
<li>Visibility, PropertyHookType & PropertyAccessMode are enums (BC break)</li>
<li>removed deprecated stuff</li>
<li>addTrait() second argument is deprecated (BC break)</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.1.92025-08-06T17:46:28ZReleased version 4.1.9<ul>
<li>support for PHP 8.5</li>
<li>final promoted property in PHP 8.5</li>
<li>optimized global function calls</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.1.82025-03-31T00:34:28ZReleased version 4.1.8<ul>
<li><code>Factory::fromClassReflection()</code> extracts property hook bodies (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2807384246" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/172" data-hovercard-type="pull_request" data-hovercard-url="/nette/php-generator/pull/172/hovercard" href="https://github.com/nette/php-generator/pull/172">#172</a>)</li>
<li><code>Factory::fromClassReflection()</code> rejects $withBodies for interfaces</li>
<li>improved tests</li>
<li>cs</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.1.72024-11-29T01:45:49ZReleased version 4.1.7<ul>
<li>added support for PHP 8.4 features
<ul>
<li>properties hooks</li>
<li>asymmetric visibility</li>
<li>property can be abstract / final</li>
<li>interfaces can have properties</li>
</ul>
</li>
<li>added Visibility</li>
<li><code>ClassManipulator::implement()</code> can implement abstract classes</li>
<li><code>ClassManipulator::implementInterface()</code> renamed to <code>implement()</code></li>
<li>PsrPrinter is not final</li>
<li>Constant: type can be nullable</li>
<li>Factory: fixed visibility of promoted property</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.0.102024-11-29T01:44:20ZReleased version 4.0.10 (EOL)<ul>
<li><code>Extractor::extractAll()</code> fixed file comment parsing</li>
<li>Factory: $withBodies cannot be used for internal classes/functions</li>
<li>Printer: fixed falsy Attribute aren't printed (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1917507752" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/142" data-hovercard-type="pull_request" data-hovercard-url="/nette/php-generator/pull/142/hovercard" href="https://github.com/nette/php-generator/pull/142">#142</a>)</li>
<li>added Visibility</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.1.62024-09-10T09:32:20ZReleased version 4.1.6<ul>
<li>added ClassManipulator</li>
<li>Parameter & Property: <code>isNullable()</code> returns true when default value is null (possible BC break)</li>
<li>added TraitsAware::hasTrait method (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2515418524" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/163" data-hovercard-type="pull_request" data-hovercard-url="/nette/php-generator/pull/163/hovercard" href="https://github.com/nette/php-generator/pull/163">#163</a>)</li>
<li>support for PHP 8.4</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.1.52024-05-12T17:37:31ZReleased version 4.1.5<ul>
<li>added <code>PhpNamespace::getClass()</code> & <code>getFunction()</code></li>
<li>added <code>CommentAware::removeComment()</code></li>
<li>added <code>PhpFile::removeNamespace()</code></li>
<li>Factory, Extractor: sets flag readonly for promoted properties <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2289849156" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/158" data-hovercard-type="issue" data-hovercard-url="/nette/php-generator/issues/158/hovercard" href="https://github.com/nette/php-generator/issues/158">#158</a> (reverts "Factory: properties in readonly classes are not readonly")</li>
<li>ClassType: cloning includes attributes and parameters</li>
<li>GlobalFunction, Method: <code>from()</code> accepts first-class callables</li>
</ul>dgtag:github.com,2008:Repository/17694277/v4.1.42024-03-07T23:07:16ZReleased version 4.1.4<ul>
<li>PsrPrinter: opening bracket on the correct line <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2162738727" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/155" data-hovercard-type="issue" data-hovercard-url="/nette/php-generator/issues/155/hovercard" href="https://github.com/nette/php-generator/issues/155">#155</a></li>
<li>Make <code>ClassLike::from</code> return type assert the subclass type (BC break) (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2155301550" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/154" data-hovercard-type="pull_request" data-hovercard-url="/nette/php-generator/pull/154/hovercard" href="https://github.com/nette/php-generator/pull/154">#154</a>)</li>
<li><code>Dumper::dumpArray()</code>, <code>dumpArguments()</code> optimization</li>
<li>Dumper: simplified list with negative keys</li>
<li>added parameter $overwrite to <code>addMember()</code>, <code>addMethod()</code>, <code>addProperty()</code>, <code>addConstant()</code>, <code>addCase()</code> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2103205161" data-permission-text="Title is private" data-url="https://github.com/nette/php-generator/issues/152" data-hovercard-type="issue" data-hovercard-url="/nette/php-generator/issues/152/hovercard" href="https://github.com/nette/php-generator/issues/152">#152</a></li>
<li>Factory: parameters 'int $foo = null' are parsed as '?int'</li>
</ul>dg