Migrating to Version 3.0

Minimum required PHP version is 7.1.

Nette 3.0 means that you have these packages installed in version 3.0.*:

"require": {
	"nette/application": "3.0.*",
	"nette/bootstrap": "3.0.*",
	"nette/di": "3.0.*",
	"nette/forms": "3.0.*",
	"nette/http": "3.0.*",
	"nette/security": "3.0.*",
},

Warning: for other packages, install the latest version that Composer will allow! They may have different versioning. Try "*" and see what version Composer installs.

PHP 7.1 Type Hints

Nette 3.0 uses typehints for parameters and return values of methods. If you inherit from a Nette class and override any of the methods that are now typehinted, PHP throws an error similar to this:

Fatal error: Declaration of Nette\Application\UI\Component::attached($presenter) must be compatible with
Nette\ComponentModel\Component::attached(Nette\ComponentModel\IComponent $obj): void

It is necessary to add the same typehints to the rewritten method. You can use the tool to automatically add missing typehints – Nette TypeFixer. Simply call in the project directory (where the /vendor and /app folders are):

typefixer --fix my-project-dir

Of course, back up everything first.

Forms

All form elements are optional by default now. This change was introduced in Nette 2.4. Now you can remove setRequired(false).

Be sure to update netteForms.js to version 3! You can install it with npm:

npm install nette-forms

The ChoiceControl::$checkAllowedValues and MultiChoiceControl::$checkAllowedValues has been replaced with method checkDefaultValue().

Presenters & Components

Constructor of Nette\ComponentModel\Component has not been used for years and was removed in version 3.0. It's a BC break. If you call parent constructor in your component or presenter inheriting from Nette\Application\UI\Presenter, you must remove it.

Interface Nette\Application\IRouter has been changed, see old and new. Now method match() returns and constructUrl() accepts array of parameters instead of object Nette\Application\Request.

Nette now checks if each signal is sent from the same origin (ie. from the same domain and subdomain). The same-origin policy is a critical security mechanism that helps reduce possible attack vectors. If you want to allow another origins, add the annotation @crossOrigin to the handle method:

/**
 * @crossOrigin
 */
function handleXy()
{
}

This also applies to the submission of forms. If you want to allow submission from another origins, do it this way:

$form = new Nette\Application\UI\Form;
$form->allowCrossOrigin();

Dependency Injection

Support for INI files has been removed.

Direct writing of PHP code to the configuration using question marks was removed. E.g:

	setup:
		- "$service->onError[] = ?"([@Some\Logger, logApplicationError])

can be replaced by:

	setup:
		- '$onError[]' = [@Some\Logger, logApplicationError]

In your configuration files, you should use factory: PDO(...) instead of class: PDO(...).

Tag nette.presenter is not used for presenters anymore.

DI for Compiler Extensions Autors

While Nette 2.4 internally described each service as Nette\DI\ServiceDefinition, there are several definitions today, such as Nette\DI\Definitions\ImportedDefinition for imported or dynamic services, Nette\DI\Definitions\FactoryDefinition for generated inteface-based factories, Nette\DI\Definitions\AccessorDefinition for generated accessors, and Nette\DI\Definitions\ServiceDefinition for common services.

So there are several other methods to create a new definition in addition to ContainerBuilder::addDefinition(): addFactoryDefinition(), addAccessorDefinition(), addImportedDefinition().

Others

The Nette\Security\Passwords class is now used as an object, ie the methods are no longer static.

Some methods, especially from Nette Database, such as fetch() or fetchField(), return NULL instead of FALSE in case of an error (ie when there is no other row).

Interface Nette\Localization\ITranslator has been changed, see old and new.

The Nette\Http\UrlScript object, which is returned for example by Nette\Http\Request::getUrl(), is now immutable.

In new Nette\Http\Url('abcd'), the abcd represents path, not the domain. Since version 3.0, (new Nette\Http\Url('abcd'))->setScheme('http') correctly generates http:abcd instead of the previous http://abcd.

Nette\Object is deprecated since Nette 2.4 and removed from Nette 3.0, however it still exists under new name Nette\LegacyObject (name object cannot be used in PHP 7.1) in nette/deprecated package.