Upgrading to V5
So you have decided to upgrade to v5! Congratulations!!
Phalcon v5 contains a lot of changes in components and interfaces. Upgrading is going to be a time-consuming task, depending on how big and complex your application is. We hope that this document will make your upgrade journey smoother and also offer insight as to why certain changes were made and how they will help the framework in the future.
We will outline the areas that you need to pay attention to and make necessary changes so that your code can run as smoothly as it has been with v4. Although the changes are significant, it is more of a methodical task than a daunting one.
Requirements
PHP 8.1
Phalcon v5.14 supports only PHP 8.1 and above. PHP 8.1 active support has already expired, including security fixes. We will be supporting this version for a while longer, offering developers more time to upgrade their applications.
Since Phalcon 4, we have been following the PHP releases and adjusting Phalcon accordingly to work with those releases.
Installation
Phalcon can be installed using PIE.
pie install phalcon
// pie install phalcon/cphalcon-5.20.3Alternative installation
Every release of the repository ships the generated C sources of the extension in the ext/ folder. You do not need Zephir to compile Phalcon.
Clone the repository to a location on your file system and check out the release you want to install.
git clone https://github.com/phalcon/cphalcon
cd cphalcon/
git checkout tags/v5.20.3 ./Compile and install Phalcon with the bundled install script
cd ext/
./installThe script runs phpize, ./configure --enable-phalcon, make and make install for you. Outside a container it uses sudo for the make install step.
Check the module
php -m | grep phalconYou will now need to enable Phalcon. Create a file called phalcon.ini with extension=phalcon.so as its content. The file should be present in:
- Suse:
/etc/php8/conf.d/phalcon.ini - CentOS/RedHat/Fedora:
/etc/php.d/phalcon.ini - Ubuntu/Debian with Apache2:
/etc/php8/apache2/conf.d/30-phalcon.iniwith this Content: - Ubuntu/Debian with Php8-FPM:
/etc/php8/fpm/conf.d/30-phalcon.ini - Ubuntu/Debian with Php8-CLI:
/etc/php8/cli/conf.d/30-phalcon.ini
For PHP 8.+ the above paths might differ slightly.
If you prefer to run the build steps yourself (for instance to pass your own configure or compiler options), use the standard PHP extension workflow in the same folder:
cd cphalcon/ext/
phpize
./configure --enable-phalcon
make && make installIf you use the above method you will need to add the extension=phalcon.so in your php.ini both for CLI and the web server.
Upgrading from v5.23 to v5.24
Phalcon v5.24 supports PHP 8.6, fixes many bugs and makes some components faster. The changes below can affect your application. Most of them affect only a class in your application that extends a Phalcon class and overrides a method.
Callbacks
A callback that Phalcon cannot call now throws the PHP TypeError of call_user_func() or call_user_func_array(). Examples are a function or a method that does not exist, a method that is not public, and an object with no __invoke() method. In v5.23, Phalcon gave a warning and returned null. This change comes from Zephir 1.9.0. It applies, for example, to:
- The service definitions and the
callsofPhalcon\Di. - The sanitizers of
Phalcon\Filter\Filter. - The helpers of
Phalcon\Html\TagFactoryandPhalcon\Support\HelperFactory. - The dispatcher actions.
- The handlers of
Phalcon\Mvc\Micro. - The converters of the router.
- The callback of
Phalcon\Mvc\Model\Resultset::filter().
If your code checks for the warning or for null, catch TypeError.
Acl
Names With the Delimiter
Phalcon\Acl\Adapter\Memory::addRole() and addComponent() throw Phalcon\Acl\Exceptions\ForbiddenDelimiter when the name of a custom RoleInterface or ComponentInterface object contains !. The Role and Component classes already throw this exception. In v5.23, the adapter accepted the name. Thus, a role, a component and an access could share the access key of another role, component and access.
Callbacks That Cannot Be Called
Phalcon\Acl\Adapter\Memory::isAllowed() denies the access when the rule has a callback that the ACL cannot call. Examples are a function that does not exist and a method that is not public. In v5.23, the ACL ignored the callback and used only the rule. Make sure that each rule callback is a closure, a public method or a function that exists.
Access Check Events
Phalcon\Acl\Adapter\Memory::isAllowed() fires acl:afterCheckAccess also for a role that does not exist. The granted value of the event is the result of the default action. A listener of this event now also gets these checks.
isAllowed() calls fireManagerEvent() for the acl:afterCheckAccess event only when an events manager is set. A subclass that overrides the protected fireManagerEvent() method no longer gets this call when no events manager is set. The acl:beforeCheckAccess event does not change.
Annotations
Cache Files That Do Not Hold Annotations
Phalcon\Annotations\Adapter\Stream::read() returns false when the cache file does not hold a Phalcon\Annotations\Reflection object. Examples are an object of a class that is not allowed, an array, a string, an integer and null. In v5.23, read() returned that value. get() now parses the class again and writes a new cache file, the same as for a missing cache file.
Cache File Header
Phalcon\Annotations\Adapter\Stream::write() puts <?php __halt_compiler(); (Stream::FILE_HEADER) at the start of each cache file, and read() removes it. PHP stops at this header, so a web request that runs a cache file shows nothing. read() also reads the cache files of v5.23, which have no header.
v5.23 and earlier versions cannot read the new cache files. If you go back to an earlier version, clear the annotationsDir folder.
Auth
Phalcon\Auth\Manager::access() throws Phalcon\Container\Exceptions\Exception when the access gate is registered in Phalcon\Di\Di as a built object with set(). It already threw this exception for setShared(). Register the class name or a closure, so that each activation gets a new gate.
Cache and Storage
Phalcon\Cache\AbstractCache and Phalcon\Storage\Adapter\AbstractAdapter call fireManagerEvent() only when an events manager is set. A subclass that overrides the protected fireManagerEvent() method no longer gets these calls when no events manager is set. With an events manager, nothing changes.
Config
Phalcon\Config\Config::path() no longer calls has() for each key of the path. It calls has() for the full path. It calls has() for the last key only when get() returns null and the default value is not null. A subclass of Config or of its adapters that overrides has() no longer controls the key walk. The result of path() does not change. A path through a value that is not a collection still throws an Error. The message of the error now names get() instead of has().
Phalcon\Config\Config::setData() calls validateType() only when the config has a type. A subclass of Config or of its adapters that overrides the protected validateType() method no longer gets this call when the config has no type. With a type, nothing changes.
Container Definitions
The factory closure that Phalcon\Container\Definition\Processor\ObjectProcessor::process() sets now declares one optional parameter, the container. Phalcon\Container\Definition\ServiceDefinition::buildService() already calls the factory with the container. A call with no arguments still works, and the returned object does not change.
Db References
SQLite Composite Keys
Phalcon\Db\Adapter\Pdo\Sqlite::describeReferences() gives one reference for each foreign key. A composite key is one reference with all its columns, in the order of the key. In v5.23, it gave one reference for each column of the key.
The name of each reference comes from the id of PRAGMA foreign_key_list (foreign_key_<id>), not from the row number. For a table with only single-column keys, the names do not change. For a table with a composite key, the names of the keys that come after it in PRAGMA foreign_key_list change, because there are fewer references.
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
user_id INT REFERENCES users (id),
ca INT,
cb INT,
FOREIGN KEY (ca, cb) REFERENCES customers (a, b)
);| Reference | v5.23 | v5.24 |
|---|---|---|
foreign_key_0 |
ca to customers.a |
['ca', 'cb'] to customers ['a', 'b'] |
foreign_key_1 |
cb to customers.b |
['user_id'] to users ['id'] |
foreign_key_2 |
user_id to users.id |
- |
PostgreSQL Referenced Schema
Phalcon\Db\Dialect\Postgresql::describeReferences() gives the schema of the referenced table as REFERENCED_TABLE_SCHEMA, and Phalcon\Db\Adapter\Pdo\Postgresql::describeReferences() gives it in Reference::getReferencedSchema(), for example public. In v5.23, both gave the name of the database. If your code compares getReferencedSchema() with the name of the database, compare it with the name of the schema.
<?php
// billing.invoices has a foreign key to public.customers
$references = $connection->describeReferences('invoices', 'billing');
foreach ($references as $reference) {
// v5.23: the name of the database
// v5.24: 'public'
echo $reference->getReferencedSchema(), PHP_EOL;
}Flash
Phalcon\Flash\AbstractFlash returns the default message template as a constant, and it does not call toInterpolate() for the template. A subclass of Phalcon\Flash\Direct or Phalcon\Flash\Session that overrides the protected static toInterpolate() method gets one call for each message with automatic HTML, instead of two. The output does not change.
Html Link
Phalcon\Html\Link\LinkProvider::getLinks() and Phalcon\Html\Link\EvolvableLinkProvider::getLinks() return arrays with spl_object_id() keys (integers). In v5.23, the keys came from spl_object_hash() (strings). If your code makes or finds these keys with spl_object_hash(), use spl_object_id(). getLinksByRel() does not change.
Mvc Model
Source Attribute
Phalcon\Mvc\Model\Manager::getModelSource() reads the Phalcon\Annotations\Models\MetaData\Source attribute of a model class when the annotations service uses Phalcon\Annotations\AttributesReader. A model with #[Source('x')] and no setSource() call now uses the table x, with the model prefix. In v5.23, it used the name of its class. A Source attribute with a table that is missing, empty or not a string throws Phalcon\Mvc\Model\Exception. With the default docblock reader, nothing changes.
Resultset Cache
Phalcon\Mvc\Model\Resultset\Simple and Phalcon\Mvc\Model\Resultset\Complex no longer put their cache in the serialized data (serialize() and __serialize()). A resultset that comes from the models cache, or from unserialize(), returns null from getCache(). In v5.23, it returned a copy of the cache with no connection. If your code needs the cache, get the modelsCache service from the container. In data that an earlier version serialized, Phalcon ignores the cache entry.
Mvc Router
Phalcon\Mvc\Router\Route::getIndexData() calls getCompiledHostName() only when the route has a host name. For a route with no host name, getIndexData()[3] is null, also when a subclass overrides getCompiledHostName(). Routing does not change.
Paginator
Phalcon\Paginator\Adapter\AbstractAdapter creates the repository in its constructor. A custom adapter that overrides __construct() must call parent::__construct(). If it does not, getRepository() throws an Error.
<?php
namespace App\Paginator;
use Phalcon\Paginator\Adapter\AbstractAdapter;
class Invoices extends AbstractAdapter
{
public function __construct(array $config)
{
parent::__construct($config);
// ...
}
}PHQL Settings
The PHQL parser reads orm.enable_literals and orm.cache_level from Phalcon\Support\Settings. A value that you set with Phalcon\Mvc\Model::setup() (phqlLiterals) or with Settings::set() has priority over the INI value. In v5.23, the parser used only the INI value.
Thus, when phqlLiterals is false, a PHQL statement with a literal throws Phalcon\Mvc\Model\Exception. In v5.23, the statement runs.
<?php
use Phalcon\Mvc\Model;
Model::setup(['phqlLiterals' => false]);
// v5.23: the statement runs
// v5.24: Phalcon\Mvc\Model\Exception
$invoices = $modelsManager->executeQuery(
'SELECT * FROM Invoices WHERE inv_status_flag = 1'
);Use bound parameters in place of the literals:
<?php
$invoices = $modelsManager->executeQuery(
'SELECT * FROM Invoices WHERE inv_status_flag = :status:',
[
'status' => 1,
]
);Queue
Phalcon\Queue\Consumer\Worker::handleSignal() has a second optional parameter. A subclass that overrides this method must declare the same parameters. If it does not, PHP stops with a fatal error when it loads the class.
<?php
namespace App\Queue;
use Phalcon\Queue\Consumer\Worker as PhalconWorker;
class Worker extends PhalconWorker
{
public function handleSignal(int $signal, ?array $info = null): void
{
parent::handleSignal($signal, $info);
}
}Return Types
Some methods declare a different return type in v5.24. The returned values do not change.
| Method | v5.23 | v5.24 |
|---|---|---|
Phalcon\Contracts\Db\Adapter\Adapter::fetchColumn() |
string|bool |
mixed |
Phalcon\Db\Adapter\AbstractAdapter::fetchColumn() |
string|bool |
mixed |
Phalcon\Db\Dialect::checkColumnType() |
string |
int |
Phalcon\Http\Request\Bag\AbstractBag::normalizeKey() |
string |
int|string |
Phalcon\Mvc\Model\Query::getCache() |
Phalcon\Db\Adapter\AdapterInterface |
?Phalcon\Cache\CacheInterface |
fetchColumn()returns the value from the database driver, for example anint, afloat, astringornull, orfalsewhen the query returns no rows. A class that overrides it can keep thestring|boolreturn type.normalizeKey()returns anintkey as anint. A class that overrides it can keep thestringreturn type.- A class that overrides
checkColumnType()orgetCache()must declare a compatible return type:intforcheckColumnType(), and?Phalcon\Cache\CacheInterfaceorPhalcon\Cache\CacheInterfaceforgetCache(). If it does not, PHP stops with a fatal error when it loads the class.
Security
Phalcon\Encryption\Security::hash() uses the work factor (getWorkFactor(), default 10) when the cost option is empty (null, 0, '0', false or ''), the same as when the option is not set. In v5.23, it used the cost 4. The new hashes take more time to make. checkHash() still verifies the earlier hashes, because each hash contains its cost.
<?php
use Phalcon\Encryption\Security;
$security = new Security();
$hash = $security->hash('s3cr3t', ['cost' => 0]);
// v5.23: '$2y$04$...'
// v5.24: '$2y$10$...'hash() also changes a numeric string cost option to an integer. A fractional value, for example '5.7', becomes 5. In v5.23, the CRYPT_BLOWFISH_A and CRYPT_BLOWFISH_X algorithms put the string in the salt ($2a$5.7$), and crypt() returned the failure string *0. Integer costs and integer strings, for example '5', give the same hashes as before.
Session
Phalcon\Session\Adapter\AbstractAdapter and Phalcon\Session\Adapter\Noop implement SessionIdInterface with create_sid(): string. This removes a PHP 8.6 deprecation.
- A subclass that overrides
create_sid()must declare thestringreturn type. - The adapter makes the new session IDs, as 32 hex characters. Thus,
session.sid_lengthandsession.sid_bits_per_characterno longer apply to these adapters. - A custom handler that implements
SessionHandlerInterfacedirectly must addcreate_sid()andvalidateId(), to prevent the PHP 8.6 deprecation.
Support Collection
Phalcon\Support\Collection::remove() no longer calls has(), and it calls the protected processKey() method one time instead of two. A subclass that overrides has() no longer controls what remove(), __unset() and offsetUnset() do.
Phalcon\Support\Collection::setData() calls validateType() only when the collection has a type. A subclass that overrides the protected validateType() method no longer gets this call when the collection has no type. This is also true for the calls from the constructor, init(), set(), offsetSet() and __set(). With a type, nothing changes.
Support Debug
Phalcon\Support\Debug records the output buffer level when you create it. onUncaughtException() discards all the output buffers that start after that point. It keeps the buffers that started before it, for example from output_buffering or zlib.output_compression in php.ini. In v5.23, it discarded only the top buffer, also when that buffer started before Debug was created. To discard the output of your own buffers, create Debug before you start them.
Volt
The Volt parser no longer has the {% cache %} and {% endcache %} tags. A template with these tags gives a syntax error. Remove the tags from your templates.
Upgrading from v5.22 to v5.23
Phalcon v5.23 makes many components faster. Most of these changes do not change what your application sees. The changes below can affect your application. Most of them affect only a class in your application that extends a Phalcon class and overrides a method.
Container Definitions
A subclass of Phalcon\Container\Definition\ServiceDefinition that overrides the protected checkFrozen() method gets the call from the setters only when the definition is frozen. In v5.22, it got the call on each setter call.
Db Dialect
Plain Columns
Phalcon\Db\Dialect::getSqlColumn() resolves a plain column ([field, domain, alias]) with prepareQualified() directly. Phalcon\Mvc\Model\Query uses this form for each model attribute. A dialect subclass that overrides the public getSqlExpression() method no longer gets the call (with a qualified expression) from getSqlColumn() for such a column. An override of prepareQualified() gets the same calls as before. The scalar ([array, ...]), * and typed (['type' => ...]) column forms still call getSqlExpression(). The SQL does not change.
Columns With No Alias
Phalcon\Db\Dialect::getSqlColumn() returns the column SQL directly when the column has no alias. A dialect subclass that overrides the protected prepareColumnAlias() method no longer gets the call (with a null alias) from getSqlColumn() for such a column. The calls for a column with an alias ([field, domain, alias] with an alias that is not empty, or an alias or sqlAlias key) are the same as before. The SQL does not change.
Http Response
Phalcon\Http\Response::sendHeaders() calls fireManagerEvent() for the response:beforeSendHeaders and response:afterSendHeaders events only when an events manager is set. A subclass of Response that overrides the protected fireManagerEvent() method no longer gets these two calls when no events manager is set. With an events manager, nothing changes.
Mvc Micro
When the router service has the default definition (the Phalcon\Mvc\Router class name, as in Phalcon\Di\FactoryDefault), Phalcon\Mvc\Micro::getRouter() gets the router without its two default routes. getRouter() removes these routes with clear() in all cases. This change has three effects:
- The routes of a Micro application get route IDs that are 2 lower. Code that reads the IDs with
getRouteId()is not affected. - The
di:beforeServiceResolveanddi:afterServiceResolveevents get"parameters" => [false]for therouterservice. In v5.22, they gotnull. - A
Microsubclass that overridesgetSharedService()no longer gets theroutercall fromgetRouter()for the default definition.
Mvc Model
Phalcon\Mvc\Model::cloneResultMap() reads the model metadata only when it needs it. For a row with no null value, it does not need the metadata. This has two effects for such a row:
- A hydrated model does not get its
modelsMetaDataproperty at hydration.dump()andvar_dump()shownullfor this property until the firstgetModelsMetaData()call. - When the Di container has no
modelsMetadataservice, a directcloneResultMap()call no longer throws an exception.find(),findFirst()and PHQL read the metadata before the hydration, so for them nothing changes.
Mvc Router
Matches After a Static Route
Phalcon\Mvc\Router::getMatches() and Phalcon\Cli\Router::getMatches() return an empty array after a static-route match, or when no route matches. In v5.22, they returned the matches of an earlier handle() call. If your code reads the matches after such a request, it now gets an empty array.
Route Constructor
Phalcon\Mvc\Router\Route::__construct() stores the HTTP methods directly and does not call via(). A subclass that overrides via() does not get the call from the constructor. A call to setHttpMethods() or via() still runs the override.
Volt Compiler
Compilation State
Phalcon\Mvc\View\Engine\Volt\Compiler resets the compilation state at the start of each compilation in compileSource(), and not at the start of each compile() call. compileFile() and compileString() call compileSource(). The compilation state is in these protected properties: extended, extendedBlocks, blocks, level, foreachLevel, blockLevel and exprLevel.
This change affects your application only if one of your classes extends the Volt compiler:
- When
compile()uses the compiled file, the state stays from the last compilation. A subclass that reads these properties after such acompile()call gets that state. In v5.22, it got the reset values. - A subclass that overrides
compileSource()and does not call the parent method does not get the reset.
Volt Output
The output of Volt can change. When one compiler compiles more than one template, a template no longer gets the blocks or the {% extends %} state of an earlier template. The Volt engine of Phalcon\Mvc\View uses one compiler for all the templates.
For example, login.volt extends base.volt and makes the header block empty. main.volt extends base.volt and does not change the header block. In v5.22, main.volt compiled after login.volt had an empty header block. In v5.23, it has the header block of base.volt.
Compiled templates made before the upgrade can have the old output. Remove the compiled templates after the upgrade, so that the compiler makes them again.
Template Paths
Phalcon\Mvc\View\Engine\Volt\Compiler::compile() keeps the virtual path of each template path. The virtual path comes from realpath() and the separator option. The compiler keeps it when the path option is a string that is not empty and the template file exists. realpath() runs one time for each template path and compiler instance.
The compiler uses the kept path until the next setOptions() or setOption() call. This is also true when one of these changes occurs after the first compile() call:
- A template file is moved or removed.
- A symbolic link in the template path changes.
- The current directory changes (for a relative template path).
clearstatcache() does not clear the kept paths. A subclass that changes the protected options property directly does not clear them. A closure in the path option is called on each call, as before.
Upgrading from v5.20 to v5.21
Phalcon v5.21 adds native types to class properties that did not have a type. Some of these properties now have an object type. For example, the $eventsManager property is now ?Phalcon\Events\ManagerInterface.
This change affects your application only if one of your classes extends a Phalcon class and declares one of these properties again. PHP requires that a child class declares an inherited property with the same type as the parent class. If the types are not the same, PHP stops with a fatal error when it loads your class:
Fatal error: Type of App\Mvc\View::$eventsManager must be ?Phalcon\Events\ManagerInterface (as in class Phalcon\Mvc\View)To correct the error, do one of these steps:
- Remove the property from your class. Your class inherits the property from the Phalcon class.
- Declare the property with the same type as the Phalcon class.
<?php
namespace App\Mvc;
use Phalcon\Events\ManagerInterface;
use Phalcon\Mvc\View as PhalconView;
class View extends PhalconView
{
// v5.20 - causes a fatal error in v5.21
// protected $eventsManager;
// v5.21
protected ?ManagerInterface $eventsManager = null;
}New Property Types
The properties below had no type in v5.20. In v5.21 they have an object type. The list shows the class that declares each property. A class that extends one of these classes inherits the new type. For example, Phalcon\Db\Adapter\Pdo\Mysql inherits $eventsManager from Phalcon\Db\Adapter\AbstractAdapter.
Changes to private properties are not in the list, because they do not affect a child class.
Container
Phalcon\Container\Container- Changed
$resolverfrom no type toPhalcon\Container\Resolver\Resolver
- Changed
DataMapper
Phalcon\DataMapper\Pdo\Connection\AbstractConnection- Changed
$profilerfrom no type toPhalcon\DataMapper\Pdo\Profiler\ProfilerInterface
- Changed
Phalcon\DataMapper\Query\AbstractQuery- Changed
$bindfrom no type toPhalcon\DataMapper\Query\Bind - Changed
$connectionfrom no type toPhalcon\DataMapper\Pdo\Connection
- Changed
Db
Phalcon\Db\Adapter\AbstractAdapter- Changed
$dialectfrom no type toPhalcon\Db\DialectInterface - Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Di
Phalcon\Di\Di- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Domain
Phalcon\Domain\Payload\Payload- Changed
$exceptionfrom no type to?Throwable
- Changed
Encryption
Phalcon\Encryption\Crypt- Changed
$padFactoryfrom no type toPhalcon\Encryption\Crypt\PadFactory
- Changed
Phalcon\Encryption\Security- Changed
$randomfrom no type toPhalcon\Encryption\Security\Random
- Changed
Phalcon\Encryption\Security\Uuid\AbstractUuid- Changed
$nodeProvider(static) from no type to?Phalcon\Encryption\Security\Uuid\NodeProviderInterface
- Changed
Events
Phalcon\Events\AbstractEventsAware- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Filter
Phalcon\Filter\Validation- Changed
$messagesfrom no type toPhalcon\Messages\Messages
- Changed
Flash
Phalcon\Flash\AbstractFlash- Changed
$escaperServicefrom no type to?Phalcon\Html\Escaper\EscaperInterface - Changed
$sessionServicefrom no type to?Phalcon\Session\ManagerInterface
- Changed
Forms
Phalcon\Forms\Element\AbstractElement- Changed
$formfrom no type to?Phalcon\Forms\Form - Changed
$messagesfrom no type toPhalcon\Messages\Messages - Changed
$tagFactoryfrom no type to?Phalcon\Html\TagFactory
- Changed
Phalcon\Forms\Form- Changed
$messagesfrom no type toPhalcon\Messages\Messages - Changed
$tagFactoryfrom no type to?Phalcon\Html\TagFactory - Changed
$validationfrom no type to?Phalcon\Filter\Validation\ValidationInterface
- Changed
Phalcon\Forms\Manager- Changed
$locatorfrom no type toPhalcon\Forms\FormsLocator
- Changed
Mvc
Phalcon\Mvc\Micro- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface - Changed
$modelBinderfrom no type to?Phalcon\Mvc\Model\BinderInterface - Changed
$routerfrom no type to?Phalcon\Mvc\RouterInterface
- Changed
Phalcon\Mvc\Model- Changed
$modelsManagerfrom no type to?Phalcon\Mvc\Model\ManagerInterface - Changed
$modelsMetaDatafrom no type to?Phalcon\Mvc\Model\MetaDataInterface
- Changed
Phalcon\Mvc\Model\Binder- Changed
$cachefrom no type to?Phalcon\Cache\Adapter\AdapterInterface
- Changed
Phalcon\Mvc\Model\Eager\Loader- Changed
$managerfrom no type toPhalcon\Mvc\Model\ManagerInterface
- Changed
Phalcon\Mvc\Model\Manager- Changed
$builderfrom no type to?Phalcon\Mvc\Model\Query\BuilderInterface - Changed
$containerfrom no type to?Phalcon\Di\DiInterface - Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Phalcon\Mvc\Model\MetaData- Changed
$adapterfrom no type to?Phalcon\Cache\Adapter\AdapterInterface - Changed
$containerfrom no type to?Phalcon\Di\DiInterface - Changed
$strategyfrom no type to?Phalcon\Mvc\Model\MetaData\Strategy\StrategyInterface
- Changed
Phalcon\Mvc\Model\Query- Changed
$containerfrom no type to?Phalcon\Di\DiInterface - Changed
$transactionfrom no type to?Phalcon\Mvc\Model\TransactionInterface
- Changed
Phalcon\Mvc\Model\Query\Status- Changed
$modelfrom no type to?Phalcon\Mvc\ModelInterface
- Changed
Phalcon\Mvc\Model\Transaction- Changed
$managerfrom no type to?Phalcon\Mvc\Model\Transaction\ManagerInterface - Changed
$rollbackRecordfrom no type to?Phalcon\Mvc\ModelInterface
- Changed
Phalcon\Mvc\Model\Transaction\Failed- Changed
$recordfrom no type to?Phalcon\Mvc\ModelInterface
- Changed
Phalcon\Mvc\Model\Transaction\Manager- Changed
$containerfrom no type to?Phalcon\Di\DiInterface
- Changed
Phalcon\Mvc\Model\ValidationFailed- Changed
$modelfrom no type toPhalcon\Mvc\ModelInterface
- Changed
Phalcon\Mvc\Router- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface - Changed
$matchedRoutefrom no type to?Phalcon\Mvc\Router\RouteInterface - Changed
$pendingCachefrom no type to?Phalcon\Cache\Adapter\AdapterInterface
- Changed
Phalcon\Mvc\Url- Changed
$routerfrom no type to?Phalcon\Mvc\RouterInterface
- Changed
Phalcon\Mvc\View- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Phalcon\Mvc\View\Engine\AbstractEngine- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Phalcon\Mvc\View\Engine\Volt- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Phalcon\Mvc\View\Engine\Volt\Compiler- Changed
$containerfrom no type to?Phalcon\Di\DiInterface
- Changed
Phalcon\Mvc\View\Simple- Changed
$eventsManagerfrom no type to?Phalcon\Events\ManagerInterface
- Changed
Removed Property Types
In v5.20.3, the properties below lost their type. This affects you only if you upgrade from v5.20.0, v5.20.1 or v5.20.2. If your class declares one of these properties again with the array type, remove the type. If you do not, PHP stops with a fatal error:
// PHP 8.1 - 8.4
Fatal error: Type of App\Http\Request::$queryFilters must not be defined (as in class Phalcon\Http\Request)
// PHP 8.5
Fatal error: Type of App\Http\Request::$queryFilters must be omitted to match the parent definition in class Phalcon\Http\RequestHttp
Phalcon\Http\Request- Changed
$queryFiltersfromarrayto no type - Changed
$trustedProxiesfromarrayto no type
- Changed
Phalcon\Http\Response\Headers- Changed
$headersfromarrayto no type
- Changed
Removed Properties
The properties below do not exist in v5.21. If your class reads or writes one of them, change your code.
Phalcon\Encryption\Crypt\PadFactory::$exception. UsegetExceptionClass()instead.Phalcon\Flash\AbstractFlash::$interpolator. The class now usestoInterpolate()fromPhalcon\Traits\Support\Helper\Str\InterpolateTrait.
General Notes
One of the biggest changes with this release is that we no longer have top-level classes. All top-level classes have been moved into relevant namespaces (except Phalcon\Tag). For instance Phalcon\Loader has been moved to Phalcon\Autoload\Loader. This change was necessary for the future expansion of the project.
Summary
| v4 | v5 |
|---|---|
Phalcon\Cache |
Phalcon\Cache\Cache |
Phalcon\Collection |
Phalcon\Support\Collection |
Phalcon\Config |
Phalcon\Config\Config |
Phalcon\Container |
Phalcon\Container\Container |
Phalcon\Crypt |
Phalcon\Encryption\Crypt |
Phalcon\Debug |
Phalcon\Support\Debug |
Phalcon\Di |
Phalcon\Di\Di |
Phalcon\Escaper |
Phalcon\Html\Escaper |
Phalcon\Exception |
Removed |
Phalcon\Filter |
Phalcon\Filter\Filter |
Phalcon\Helper |
Removed in favor of Phalcon\Support\Helper |
Phalcon\Loader |
Phalcon\Autoload\Loader |
Phalcon\Logger |
Phalcon\Logger\Logger |
Phalcon\Kernel |
Removed |
Phalcon\Registry |
Phalcon\Support\Registry |
Phalcon\Security |
Phalcon\Encryption\Security |
Phalcon\Text |
Removed in favor of Phalcon\Support\Helper |
Phalcon\Url |
Phalcon\Mvc\Url |
Phalcon\Validation |
Phalcon\Filter\Validation |
Phalcon\Version |
Phalcon\Support\Version |
Changes
Acl
The ACL component has had some methods and components renamed. The functionality remains the same as in previous versions.
- Renamed
Phalcon\Acl\ComponentAwaretoPhalcon\Acl\ComponentAwareInterface - Renamed
Phalcon\Acl\RoleAwaretoPhalcon\Acl\RoleAwareInterface
Acl\Adapter\Memory - Acl\Adapter\AdapterInterface
- Added
getInheritedRoles()to return an array of the inherited roles in the adapter.
Annotations
Application
Phalcon\Application\AbstractApplication
- The
getEventsManager()now returns aPhalcon\Events\ManagerInterfaceornull
Assets
The Assets component has had changes to the interface as well and some methods were renamed. The functionality remains the same as in previous versions.
Phalcon\Assets\Asset
getAssetKey()now usessha256to compute the key- Renamed
getLocal()toisLocal() - Renamed
setLocal()tosetIsLocal()
Phalcon\Assets\Collection
- The class now uses
ArrayIteratorinstead ofIterator - Renamed
getLocal()toisLocal() - Renamed
setLocal()tosetIsLocal() - Renamed
getTargetLocal()togetTargetIsLocal() - Renamed
setTargetLocal()tosetTargetIsLocal() - Removed
getPosition(),current(),key(),next(),rewind(),valid()
Phalcon\Assets\Inline
getAssetKey()now usessha256to compute the key
Phalcon\Assets\Manager
__construct()requires aPhalcon\Html\TagFactoryas the first parameter
public function __construct(
Phalcon\Html\TagFactory $tagFactory,
array $options = []
)addCss()now requires$localto bebooland$attributesto be an array
public function addCss(
string $path,
bool $local = true,
bool $filter = true,
array $attributes = [],
string $version = null,
bool $autoVersion = false
): ManageraddInlineCss()now requires$filterto bebooland$attributesto be an array
public function addInlineCss(
string $content,
bool $filter = true,
array $attributes = []
): ManageraddJs()now requires$localto bebooland$attributesto be an array
public function addJs(
string $path,
bool $local = true,
bool $filter = true,
array $attributes = [],
string $version = null,
bool $autoVersion = false
): ManageraddInlineJs()now requires$filterto bebooland$attributesto be an array
public function addInlineJs(
string $content,
bool $filter = true,
array $attributes = []
): Manager- Added
has()method to return if a collection exists
Autoload
The Autoload\Loader component has been moved from the parent namespace. Some method names have been changed and new functionality introduced.
Phalcon\Autoload\Loader
__construct(bool $isDebug = false)The constructor now accepts a boolean, which allows the loader to collect and store debug information during the discovery and loading process of files, classes, etc. If the variable is set totrue,getDebug()will return an array with all the debugging information during the autoload operation. This mode is only for debugging purposes and must not be used in production environments.
use Phalcon\Autoload\Loader;
use Adapter\Another;
$loader = new Loader(true);
$loader
->addNamespace('Base', './Namespaces/Base/')
->addNamespace('Adapter', './Namespaces/Adapter/')
->addNamespace('Namespaces', './Namespaces/')
;
$loader->autoload(Another::class);
var_dump($loader->getDebug());
// [
// 'Loading: Adapter\Another',
// 'Class: 404: Adapter\Another',
// 'Require: 404: ./Namespaces/Adapter/Another.php',
// 'Require: ./Namespaces/Another.php',
// 'Namespace: Namespaces\Adapter - ./Namespaces/Another.php',
// ];add*methods have been introduced to help with the setup of the autoloaderaddClass(string $name, string $file): LoaderaddDirectory(string $directory): LoaderaddExtension(string $extension): LoaderaddFile(string $file): LoaderaddNamespace(string $name, string|array $directories, bool $prepend = false): Loader
getCheckedPath()now returns either a string or anull(if not populated yet)getDebug()returns an array of debug information, if the Loader has been instantiated with$isDebug = truegetDirs()has been renamed togetDirectories()getFoundPath()now returns either a string or anull(if not populated yet)registerClasses()has been renamed tosetClasses()registerDirs()has been renamed tosetDirectories()registerExtensions()has been renamed tosetExtensions()setExtensions()now accepts a second parameter (bool$merge) which allows you to merge the data set with what is already set in the LoaderregisterFiles()has been renamed tosetFiles()registerNamespaces()has been renamed tosetNamespaces()
Cache
The Cache component has been moved to the Cache namespace.
Phalcon\Cache\AdapterFactory
- The constructor now requires a
Phalcon\Storage\SerializerFactoryto be passed as the first parameter - The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Phalcon\Cache\CacheFactory
- A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Phalcon\Cache\Cache
- Moved
Phalcon\CachetoPhalcon\Cache\Cache - The component has been refactored and the dependency to
PSRhas been removed. more
Phalcon\Cache\CacheInterface
- A new interface has been introduced (
Phalcon\Cache\CacheInterface) to offer more flexibility when extending the cache object.
Cli
Collection
The Collection component has been moved to the Support namespace. more
Config
The Config component has been moved to the Config namespace.
Phalcon\Config\Config
- Moved
Phalcon\ConfigtoPhalcon\Config\Config
Phalcon\Config\ConfigInterface
- A new interface has been introduced (
Phalcon\Config\ConfigInterface) to offer more flexibility when extending the config object.
Container
The Container component has been removed from the framework. It is in our roadmap to develop a new container that will support auto wiring, as well as providers. Additionally, the container will be designed and implemented in such a way that could be used as a PSR-11 container (with the help of a Proxy class).
Crypt
The Crypt component has been moved to the Encryption namespace. more
DataMapper
Db
Phalcon\Db\Adapter\Pdo\AbstractPdo
- Changed
connect(array descriptor = null): booltoconnect(array descriptor = []): void - Changed
execute(string $sqlStatement, $bindParams = null, $bindTypes = null): booltoexecute(string $sqlStatement, array $bindParams = [], array $bindTypes = []) -> bool - Changed
getErrorInfo()togetErrorInfo(): array - Changed
getInternalHandler(): \PDOtogetInternalHandler(): mixed - Changed
lastInsertId($sequenceName = null): int | booltolastInsertId(string $name = null) -> string | bool - Changed
query(string $sqlStatement, $bindParams = null, $bindTypes = null): ResultInterface | booltoquery(string $sqlStatement, array $bindParams = [], array $bindTypes = []): ResultInterface | bool
Phalcon\Db\Adapter\Pdo\Mysql
- Changed bind type for
Column::TYPE_BIGINTto beColumn::BIND_PARAM_STR - Added bind type for
Column::TYPE_BINARYto cater toVARBINARYandBINARYfields - Added support for comments
Phalcon\Db\Adapter\Pdo\Postgresql
- Changed bind type for
Column::TYPE_BIGINTto beColumn::BIND_PARAM_STR - Added support for comments
Phalcon\Db\Adapter\AbstractAdapter
- Changed property
connectionIdtoint - Added property
realSqlStatementto store the real SQL statement executed - Changed
delete($table, $whereCondition = null, $placeholders = null, $dataTypes = null): booltodelete($table, string $whereCondition = null, array $placeholders = [], array $dataTypes = []): bool - Changed
fetchAll(string $sqlQuery, int $fetchMode = Enum::FETCH_ASSOC, $bindParams = null, $bindTypes = null): arraytofetchAll(string $sqlQuery, int $fetchMode = Enum::FETCH_ASSOC, array $bindParams = [], array $bindTypes = []): array - Changed
fetchOne(string $sqlQuery, $fetchMode = Enum::FETCH_ASSOC, $bindParams = null, $bindTypes = null): arraytofetchOne(string $sqlQuery, $fetchMode = Enum::FETCH_ASSOC, array $bindParams = [], array $bindTypes = []): array - Changed
getEventsManager(): ManagerInterfacetogetEventsManager(): ManagerInterface | null - Added
getSQLVariables(): arrayto return the SQL variables used - Added
supportsDefaultValue(): boolto allow checking for adapters that support theDEFAULTkeyword
Phalcon\Db\Adapter\AdapterInterface
- Changed
close(): booltoclose(): void - Changed
connect(array $descriptor = null): booltoconnect(array $descriptor = []): void - Changed
delete($table, $whereCondition = null, $placeholders = null, $dataTypes = null): booltodelete($table, string $whereCondition = null, array $placeholders = [], array $dataTypes = []): bool - Changed
execute(string $sqlStatement, $placeholders = null, $dataTypes = null): booltoexecute(string $sqlStatement, array $bindParams = [], array $bindTypes = []): bool - Changed
fetchAll(string $sqlQuery, int $fetchMode = 2, $placeholders = null): arraytofetchAll(string $sqlQuery, int $fetchMode = 2, array $bindParams = [], array $bindTypes = []): array - Changed
fetchOne(string $sqlQuery, int $fetchMode = 2, $placeholders = null): array;tofetchOne(string $sqlQuery, int $fetchMode = 2, array $bindParams = [], array $bindTypes = []): array - Added
getDefaultValue(): RawValue - Changed
getInternalHandler(): \PDOtogetInternalHandler(): mixed - Changed
lastInsertId($sequenceName = null): int | booltolastInsertId(string $name = null) -> string | bool - Changed
query(string $sqlStatement, $bindParams = null, $bindTypes = null): ResultInterface | booltoquery(string $sqlStatement, array $bindParams = [], array $bindTypes = []): ResultInterface | bool - Added
supportsDefaultValue(): bool
Phalcon\Db\Adapter\PdoFactory
- Added
getExceptionClass()to return the exception class for the factory - Renamed
getAdapters()togetServices()
Phalcon\Db\Dialect\*
- Added support for comments
- Added support for
SMALLINTfor Postgresql
Phalcon\Db\Result\ResultPdo
- Renamed
Phalcon\Db\Result\PdotoPhalcon\Db\Result\ResultPdo
Phalcon\Db\Column
- Added support for comments
- Added
TYPE_BINARYconstant - Added
TYPE_VARBINARYconstant - Added
getComment(): string | null
Phalcon\Db\DialectInterface
- Changed
getSqlExpression(array $expression, string $escapeChar = null, $bindCounts = null): string;togetSqlExpression(array $expression, string $escapeChar = null, array $bindCounts = []): string
Phalcon\Db\Dialect
- Changed
getColumnList(array $columnList, string $escapeChar = null, $bindCounts = null): stringtogetColumnList(array $columnList, string $escapeChar = null, array $bindCounts = []): string - Changed
getSqlColumn($column, string $escapeChar = null, $bindCounts = null): stringtogetSqlColumn($column, string $escapeChar = null, array $bindCounts = []): string - Changed
getSqlExpression(array $expression, string $escapeChar = null, $bindCounts = null): string;togetSqlExpression(array $expression, string $escapeChar = null, array $bindCounts = []): string
Phalcon\Db\Exception
- Changed
Phalcon\Db\Exceptionto extend\Exception
Phalcon\Db\Profiler
- Changed
Phalcon\Db\Profilerto usehrtime()internally to calculate metrics
Phalcon\Db\ResultInterface
- Changed
dataSeek(long $number)todataseek(int $number)
Debug
The Debug component has been moved to the Support namespace. more
Di
The Di component has been moved to the Di namespace.
Phalcon\Di\Di
- Moved
Phalcon\DitoPhalcon\Di\Di - The
tagservice now returns an instance ofPhalcon\Html\TagFactory - The (new)
helperservice returns an instance ofPhalcon\Support\HelperFactory
Dispatcher
Phalcon\Dispatcher\AbstractDispatcher
- Changed
getEventsManager(): ManagerInterfacetogetEventsManager(): ManagerInterface | null
Phalcon\Dispatcher\Exception
- Changed
Phalcon\Dispatcher\Exceptionto extend\Exception
Domain
Encryption
Phalcon\Encryption\Crypt
- Moved
Phalcon\CrypttoPhalcon\Encryption\Crypt - Two new constants introduced
DEFAULT_ALGORITHM = "sha256"andDEFAULT_CIPHER = "aes-256-cfb" - The
__constructnow setsuseSigningastrue(previouslyfalse) - The
__constructaccepts a third parameter (nullby default), which is aPhalcon\Encryption\Crypt\PadFactory
use Phalcon\Encryption\Crypt;
use Phalcon\Encryption\Crypt\PadFactory;
$padFactory = new PadFactory();
$crypt = new Crypt("aes-256-cfb", true, $padFactory);If no padFactory is passed, a new one will be created in the component.
Phalcon\Encryption\Crypt::getAvailableHashAlgos()was renamed toPhalcon\Encryption\Crypt::getAvailableHashAlgorithms()Phalcon\Encryption\Crypt::getHashAlgo()was renamed toPhalcon\Encryption\Crypt::getHashAlgorithm()Phalcon\Encryption\Crypt::setHashAlgo()was renamed toPhalcon\Encryption\Crypt::setHashAlgorithm()
Phalcon\Encryption\Crypt\CryptInterface
- Moved
Phalcon\Crypt\CryptInterfacetoPhalcon\Encryption\Crypt\CryptInterface - Changed
Phalcon\Encryption\Crypt\CryptInterface::decryptBase64()to accept astringvariable as thekey - Changed
Phalcon\Encryption\Crypt\CryptInterface::encryptBase64()to accept astringvariable as thekey - Added
Phalcon\Encryption\Crypt\CryptInterface::useSigning(bool useSigning)
Phalcon\Encryption\Crypt\Exception\Exception
- Moved
Phalcon\Crypt\ExceptiontoPhalcon\Encryption\Crypt\Exception\Exception
Phalcon\Encryption\Crypt\Exception\Mismatch
- Moved
Phalcon\Crypt\MismatchtoPhalcon\Encryption\Crypt\Exception\Mismatch
Phalcon\Encryption\Crypt
- Moved from
Phalcon\Crypt
Phalcon\Encryption\PadFactory
- Added
Phalcon\Encryption\PadFactoryto allow for different padding schemes during encryption and decryption of data
Phalcon\Encryption\Padding\*
- Added
Phalcon\Encryption\Padding\PadInterfaceto allow for custom padding classes - Added
Phalcon\Encryption\Padding\Ansi - Added
Phalcon\Encryption\Padding\Iso10126 - Added
Phalcon\Encryption\Padding\IsoIek - Added
Phalcon\Encryption\Padding\Noop - Added
Phalcon\Encryption\Padding\Pkcs7 - Added
Phalcon\Encryption\Padding\Space - Added
Phalcon\Encryption\Padding\Zero
Escaper
The Escaper component has been moved to the Html namespace. more
Events
Phalcon\Events\AbstractEventsAware
- Added abstract
Phalcon\Events\AbstractEventsAware
Phalcon\Events\Event
- Changed
public function __construct(string $type, object $source, $data = null, bool $cancelable = true)to__construct(string $type, $source = null, $data = null, bool $cancelable = true)($sourceis now nullable)
Phalcon\Events\Exception
- Changed
Phalcon\Events\Exceptionto extend\Exception
Phalcon\Events\Manager
- Added
isValidHandler(): boolto return if the internal handler is valid or not
Exception
Phalcon\Exception
The class has been removed.
Factory
Phalcon\Factory\AbstractConfigFactory
- Added abstract
Phalcon\Factory\AbstractConfigFactoryto check configuration elements
Phalcon\Factory\AbstractFactory
- Changed
init()to read fromgetServices()
Phalcon\Factory\Exception
- Changed
Phalcon\Factory\Exceptionto extend\Exception
Filter
The Filter component has been moved to the Filter namespace.
Phalcon\Filter\Filter
- Moved
Phalcon\FiltertoPhalcon\Filter\Filter
Phalcon\Filter\Exception
- Changed
Phalcon\Filter\Exceptionto extend\Exception
Phalcon\Filter\Factory
- Changed
getAdapters()togetServices()
Phalcon\Filter\Filter
- Added
__call()to allow using filter names as methods i.e.$filter->upper($input)
Phalcon\Filter\Validation
- Added
getValueByEntity()andgetValueByData()for more options to retrieve data
Phalcon\Filter\Validation\Validator\Exception
- Changed
Phalcon\Filter\Validation\Validator\Exceptionto extend\Exception
AbstractValidator.zep
- Added the ability to define
allowEmptyto any validator (in the parameters)
Phalcon\Filter\Validation\Exception
- Changed
Phalcon\Filter\Validation\Exceptionto extend\Exception
Phalcon\Filter\Validation\ValidationInterface
- Changed
add(string $field, ValidatorInterface $validator): <ValidationInterfacetoadd($field, ValidatorInterface $validator): <ValidationInterface - Changed
rule(string $field, ValidatorInterface $validator): <ValidationInterfacetorule($field, ValidatorInterface $validator): <ValidationInterface
Phalcon\Filter\Validation\ValidatorFactory
- Changed
getAdapters()togetServices()
Flash
Phalcon\Flash\AbstractFlash
- Added the ability to define CSS icon classes (
setCssIconClasses()) - Changed
getTemplate(string $cssClasses): stringtogetTemplate(string $cssClasses, string $cssIconClasses): string
Phalcon\Flash\Exception
- Changed
Phalcon\Flash\Exceptionto extend\Exception
Phalcon\Flash\Session
- Added
SESSION_KEYconstant - Changed
has($type = null): booltohas(string $type = null): bool - Changed
message(string $type, string $message): string | nulltomessage(string $type, $message): string | null
Forms
Phalcon\Forms\Element\* classes now use the new Phalcon\Html\TagFactory to generate HTML code. As a result, the functionality has changed slightly. The main difference is that a Phalcon\Html\TagFactory has to be set in the form object so that elements can be rendered. If the Phalcon\Html\TagFactory is not set, then the component will search the Di container (Phalcon\Di\DiInterface) for a service with the name tag. If you are using Phalcon\Di\FactoryDefault as your container, then the tag service is already defined for you.
Phalcon\Forms\Element\AbstractElement
- Added
getTagFactory()to return thePhalcon\Html\TagFactoryobject used internally, as well assetTagFactory(TagFactory $tagFactory): AbstractElementto set it.
Phalcon\Forms\Element\Check
Phalcon\Forms\Element\Radio
- The classes now use the
Phalcon\Html\Helper\Input\CheckboxandPhalcon\Html\Helper\Input\Radiorespectively. The classes usecheckedanduncheckedparameters to set the state of each control. If thecheckedparameter is identical to the$valuethen the control will be checked. If theuncheckedparameter is present, it will be set if the$valueis not the same as thecheckedparameter. more
Helper
The Helper component has been moved to the Support namespace. more
Html
Phalcon\Html\Escaper
- Moved
Phalcon\EscapertoPhalcon\Html\Escaper - Changed the
flagsproperty that controls the flags forhtmlspecialchars()is set to11which corresponds toENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. - Method names changed to be more verbose.
- Added
attributes(string input)for escaping HTML attributes (replacesescapeHtmlAttr()) - Added
css(string $input)for escaping CSS (replacesescapeCss() - Added
html(string $input = null)for escaping HTML (replacesescapeHtml()) - Added
js(string $input)for escaping JS (replacesescapeJs()) - Added
setFlags(int $flags)to set the flagshtmlspecialchars()(replacessetHtmlQuoteType()) - Added
url(string $input)for escaping URL strings (replacesescapeUrl()) escapeCss()now raises a deprecated warningescapeJs()now raises a deprecated warningescapeHtml()now raises a deprecated warningescapeUrl()now raises a deprecated warningsetHtmlQuoteType()now raises a deprecated warning
- Added
Phalcon\Html\Escaper\EscaperInterface
- Moved
Phalcon\Escaper\EscaperInterfacetoPhalcon\Html\Escaper\EscaperInterface - Added
attributes(string input) - Added
css(string $input) - Added
html(string $input = null) - Added
js(string $input) - Added
setFlags(int $flags) - Added
url(string $input) - Removed
escapeCss() - Removed
escapeJs() - Removed
escapeHtml() - Removed
escapeUrl() - Removed
setHtmlQuoteType()
Phalcon\Html\Escaper\Exception
- This class has been moved to this namespace
Phalcon\Escaper. - Changed
Phalcon\Html\Escaper\Exceptionto extend\Exception
Phalcon\Html\Helper
- Moved
Phalcon\HelpertoPhalcon\Html\Helper - The component has been refactored and offers more functionality now. more
Phalcon\Html\Link
- The component has been refactored and the dependency to
PSRhas been removed. more
Phalcon\Html\TagFactory
- Added
__call(string $name, array $arguments)to allow calling helper objects as methods. more - Added
has(string $name) -> boolAddedset(string $name, mixed $method): void - The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Phalcon\Html\Exception
- Changed
Phalcon\Html\Exceptionto extend\Exception
Http
Phalcon\Http\Cookie
- Changed
__construct()and made$httpOnly = false
Phalcon\Http\Cookie\Escaper
- Changed
Phalcon\Http\Request\Exceptionto extend\Exception
Phalcon\Http\Message
- The namespace has been removed
Phalcon\Http\Request
- Added
getPreferredIsoLocaleVariant(): stringto return the preferred ISO locale variant.
Phalcon\Http\Request\Exception
- Changed
Phalcon\Http\Cookie\Exceptionto extend\Exception
Phalcon\Http\Response\Cookie
- Added
isSent(): boolto return if the cookie has been sent or not
Phalcon\Http\Response\Headers
- Added
isSent(): boolto return if the headers have been sent or not
Phalcon\Http\Response\Exception
- Changed
Phalcon\Http\Response\Exceptionto extend\Exception
Phalcon\Http\Server
- The namespace has been removed
Image
Loader
The class has been moved to the Phalcon\Autoload namespace more
Logger
The Logger component has been moved to the Logger namespace.
Phalcon\Logger\Logger
- Moved
Phalcon\LoggertoPhalcon\Logger\Logger - The component has been refactored and the dependency to
PSRhas been removed. more - The interface method calls are much stricter now.
Phalcon\Logger\AbstractLogger
- Added
Phalcon\Logger\AbstractLoggerwith common functionality, to be used by packages that wish to alter interfaces to the logger while keeping the same functionality (see bridge-psr3)
Phalcon\Logger\Adapter\Stream
- Failing to write to the file will throw a
LogicExceptioninstead ofUnexpectedValueException
Phalcon\Logger\Formatter\FormatterInterface
- Changed
process(Item $item): string(previously it returnedarray|string)
Phalcon\Logger\Formatter\Json
- Changed
format()to encode JSON with the following options by default:JSON_HEX_TAG,JSON_HEX_APOS,JSON_HEX_AMP,JSON_HEX_QUOT,JSON_UNESCAPED_SLASHES,JSON_THROW_ON_ERROR,
Phalcon\Logger\AdapterFactory
- The constructor now requires a
Phalcon\Storage\SerializerFactoryto be passed as the first parameter - The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Phalcon\Logger\Exception
- Changed
Phalcon\Logger\Exceptionto extend\Exception
Phalcon\Logger\Item
- Changed
__construct(string $message, string $levelName, int $level, DateTimeImmutable $dateTime, array $context = [])(dateTimeaccepts aDateTimeImmutableobject)
Phalcon\Logger\LoggerInterface
- A new interface has been introduced (
Phalcon\Logger\LoggerInterface) to offer more flexibility when extending the cache object.
Messages
Phalcon\Messages\Exception
- Changed
Phalcon\Messages\Exceptionto extend\Exception
Mvc
Phalcon\Mvc\Micro\Collection
- Changed the methods to accept a
callableas the$handlerinstead of mixeddelete(string $routePattern, callable $handler, string $name = null)get(string $routePattern, callable $handler, string $name = null)head(string $routePattern, callable $handler, string $name = null)map(string $routePattern, callable $handler, string $name = null)mapVia(string $routePattern, callable $handler, mixed $method, string $name = null)options(string $routePattern, callable $handler, string $name = null)patch(string $routePattern, callable $handler, string $name = null)post(string $routePattern, callable $handler, string $name = null)put(string $routePattern, callable $handler, string $name = null)
Phalcon\Mvc\Micro\Exception
- Changed
Phalcon\Mvc\Micro\Exceptionto extend\Exception
Phalcon\Mvc\Model\MetaData\Strategy\Annotations
Phalcon\Mvc\Model\MetaData\Strategy\Annotations::getMetaData()will now return a string instead of an integer when encounteringBIGINTfields
Phalcon\Mvc\Model\MetaData\Stream
- Changed the constructor to accept an array
__construct(array $options = [])
Phalcon\Mvc\Model\Query\BuilderInterface
- Corrected
having()signaturehaving(string $conditions, array $bindParams = [], array $bindTypes = []) - Changed
orderBy()to accept an array or a stringorderBy(array | string $orderBy)
Phalcon\Mvc\Model\Resultset\Complex
- Changed
current()to returnmixed - Added
__serialize()and__unserialize()methods
Phalcon\Mvc\Model\Resultset\Simple
- Changed the constructor to accept
mixedfor$cache:__construct(mixed $columnMap, mixed $model, mixed $result, mixed $cache = null, bool $keepSnapshots = false) - Added
__serialize()and__unserialize()methods
Phalcon\Mvc\Model\CriteriaInterface
- Corrected
where()signaturewhere(string $conditions, mixed $bindParams = null, mixed $bindTypes = null)
Phalcon\Mvc\Model\Exception
- Changed
Phalcon\Mvc\Model\Exceptionto extend\Exception
Phalcon\Mvc\Model\ManagerInterface
- Changed
$optionsparameter to be an array: -addBelongsTo(ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasMany(ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasOne(ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasOneThrough(ModelInterface $model, mixed $fields, string $intermediateModel, mixed $intermediateFields, mixed $intermediateReferencedFields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasManyToMany(ModelInterface $model, mixed $fields, string $intermediateModel, mixed $intermediateFields, mixed $intermediateReferencedFields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface - Changed
getModelSchema(ModelInterface $model)to returnstringornull - Renamed:
existsBelongsTo()tohasBelongsTo()existsMany()tohasHasMany()existsOne()tohasHasOne()existsOneThrough()tohasHasOneThrough()existsManyToMany()tohasHasManyToMany()
Phalcon\Mvc\Model\Manager
- Changed
getEventsManager()to returnEventManagerInterfaceornull - Changed
getModelSchema(ModelInterface $model)to returnstringornull - Changed
$optionsparameter to be an array: -addBelongsTo(ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasMany(ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasOne(ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasOneThrough(ModelInterface $model, mixed $fields, string $intermediateModel, mixed $intermediateFields, mixed $intermediateReferencedFields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface-addHasManyToMany(ModelInterface $model, mixed $fields, string $intermediateModel, mixed $intermediateFields, mixed $intermediateReferencedFields, string $referencedModel, mixed $referencedFields, array options = []): RelationInterface - Marked as
@deprecated:existsBelongsTo()existsMany()existsOne()existsOneThrough()existsManyToMany()
- Added (replacing the
exists*methods):hasBelongsTo()hasHasMany()hasHasOne()hasHasOneThrough()hasHasManyToMany()
- Added
getBuilder()to return the builder that was created withcreateBuilder()(ornull)
Phalcon\Mvc\Model\ResultsetInterface
getCache()now returnsnullor an object (mixed)
Phalcon\Mvc\Model\Resultset
__construct()accepts an object in the$cacheparameter. The object has implementPhalcon\Cache\CacheInterfaceorPsr\SimpleCache\CacheInterfacegetCache()now returnsnullor an object (mixed)
Phalcon\Mvc\Router
- Changed
add(),addConnect(),addDelete(),addGet(),addHead(),addOptions(),addPatch(),addPost(),addPurge(),addPut(),addTrace(),attach()to acceptintas$position - Changed
getEventsManager()to returnManagerInterfaceornull
Phalcon\Mvc\RouterInterface
- Changed
add(),addConnect(),addDelete(),addGet(),addHead(),addOptions(),addPatch(),addPost(),addPurge(),addPut(),addTrace(),attach()to acceptintas$position
Phalcon\Mvc\Router\Exception
- Changed
Phalcon\Mvc\Router\Exceptionto extend\Exception
Phalcon\Mvc\Router\RouteInterface
getHostname()now returnsstringornullgetName()now returnsstringornull
Phalcon\Mvc\Router\Route
beforeMatch(callable $callback): RouteInterfacenow accepts acallablegetHostname()now returnsstringornullgetName()now returnsstringornull
Phalcon\Mvc\ModelInterface
- Changed
average(array $parameters = [])to accept an array - Changed
cloneResultset()to defaultkeepSnapshots = false - Changed
findFirst(mixed $parameters = null): mixed | nullto returnnullinstead offalse - Changed
getSchema(): string | nullto returnstringornull
Phalcon\Mvc\View
- Marked as
@deprecatedexists() - Added
has()(replacing theexists()method)
Phalcon\Mvc\View\Exception
- Changed
Phalcon\Mvc\View\Exceptionto extend\Exception
Phalcon\Mvc\View\Engine\Volt\Compiler
- Removed
compileCache()
Phalcon\Mvc\Url
- Moved from
Phalcon\Url
Phalcon\Mvc\Url\Exception
- Moved from
Phalcon\Url\Exception - Changed
Phalcon\Mvc\Url\Exceptionto extend\Exception
Phalcon\Mvc\Url\UrlInterface
- Moved from
Phalcon\Url\UrlInterface
Phalcon\Paginator\Exception
- Changed
Phalcon\Paginator\Exceptionto extend\Exception
Phalcon\Paginator\PaginatorFactory
- The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Registry
The Registry component has been moved to the Support namespace. more
Security
The Security component has been moved to the Encryption namespace. more
Session
Phalcon\Session\Adapter\AbstractAdapter
- Changed
gc(int $maxlifetime): int | boolto accept onlyintfor the parameter
Phalcon\Session\Adapter\Noop
- Changed
gc(int $maxlifetime): int | boolto accept onlyintfor the parameter
Phalcon\Session\Adapter\Stream
- Changed
__construct()to throw an exception if the save path is empty
Phalcon\Session\BagInterface
- Added interface for
Phalcon\Session\Bag
Phalcon\Session\Exception
- Changed
Phalcon\Session\Exceptionto extend\Exception
Storage
Phalcon\Storage\Adapter\AdapterInterface
- Added
setForever(string $key, mixed $value):to set an item in the store forever
Phalcon\Storage\Adapter\Apcu
- Added
setForever(string $key, mixed $value):to set an item in the store forever
Phalcon\Storage\Adapter\Libmemcached
- Added
setForever(string $key, mixed $value):to set an item in the store forever
Phalcon\Storage\Adapter\Memory
- Added
setForever(string $key, mixed $value):to set an item in the store forever
Phalcon\Storage\Adapter\Redis
- Added
setForever(string $key, mixed $value):to set an item in the store forever - Added
timeout,connectTimeout,retryIntervalandreadTimeoutfor constructor options
Phalcon\Storage\Adapter\Stream
- Added
setForever(string $key, mixed $value):to set an item in the store forever
Phalcon\Storage\Serializer\AbstractSerializer
- Added
__serialize()and__unserialize()methods - Added
isSuccess(): boolto return when the data was serialized/unserialized successfully
Phalcon\Storage\Serializer\Base64
- Changed
unserializeto set the data to an empty string in case of a failure
Phalcon\Storage\Serializer\Igbinary
- Changed
unserializeto set the data to an empty string in case of a failure
Phalcon\Storage\Serializer\Msgpack
- Changed
unserializeto set the data to an empty string in case of a failure
Phalcon\Storage\Serializer\Php
- Changed
unserializeto set the data to an empty string in case of a failure
Phalcon\Storage\Serializer\*
- Added stub serializers for Memcached and Redis when in need to use the built-in serializers for those storages:
Phalcon\Storage\Serializer\MemcachedIgbinaryPhalcon\Storage\Serializer\MemcachedJsonPhalcon\Storage\Serializer\MemcachedPhpPhalcon\Storage\Serializer\RedisIgbinaryPhalcon\Storage\Serializer\RedisJsonPhalcon\Storage\Serializer\RedisMsgpackPhalcon\Storage\Serializer\RedisNonePhalcon\Storage\Serializer\RedisPhp
Phalcon\Storage\Exception
- Changed
Phalcon\Storage\Exceptionto extend\Exception
Phalcon\Storage\AdapterFactory
- The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Phalcon\Storage\SerializerFactory
- The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Support
The Support namespace contains classes that are used throughout the framework. The classes moved here are:
Phalcon\Support\Collection
- Moved
Phalcon\CollectiontoPhalcon\Support\Collection get()will return thedefaultValueif thekeyis not set. It will also return thedefaultValueif thekeyis set and the value isnull. This aligns with the 3.x behavior.
Phalcon\Support\Collection\CollectionInterface
- A new interface has been introduced (
Phalcon\Support\Collection\CollectionInterface) to offer more flexibility when extending the collection object.
Phalcon\Support\Collection\ReadOnlyCollection
- This class has been renamed from
ReadOnlyin order to avoid collisions with PHP 8.x reserved words.
Phalcon\Support\Debug\Exception
- Changed
Phalcon\Support\Debug\Exceptionto extend\Exception
Phalcon\Support\Helper\Exception
- Changed
Phalcon\Support\Helper\Exceptionto extend\Exception
Phalcon\Helper\*
Arr,Fs,Json,Number, andStrstatic classes have been removed and replaced with one class per method in the relevant namespace. For examplePhalcon\Helper\Arr::has()is notPhalcon\Support\Helper\Arr\Has::__invoke()- Added
Phalcon\Support\Helper\HelperFactoryservice locator to create objects from thePhalcon\Support\Helpernamespace - Added
__call()inPhalcon\Support\Helper\HelperFactoryto offer an easier access to objects i.e.$this->helperFactory->dirFromFile()
Tag
Note, that this component will be removed in future versions of the framework.
Phalcon\Tag
- Added
preload(mixed $parameters): stringto parse preloading link headers
Text
The Phalcon\Text component has been deprecated. It has been replaced with the Phalcon\Support\HelperFactory. more
Translate
Phalcon\Translate\Adapter\AbstractAdapter
- Changed
__construct(InterpolatorFactory $interpolator, array $options = []to default to an empty array for$options
Phalcon\Translate\Adapter\Csv
- Marked as
@deprecatedexists() - Added
has()
Phalcon\Translate\Adapter\Gettext
- Marked as
@deprecatedexists() - Added
has()
Phalcon\Translate\Adapter\NativeArray
- Marked as
@deprecatedexists() - Added
has() - Added
toArray()to return the translation array back
Phalcon\Translate\Exception
- Changed
Phalcon\Translate\Exceptionto extend\Exception
Phalcon\Translate\InterpolatorFactory
- The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Phalcon\Translate\TranslateFactory
- The
getAdapters()protected method has been renamed togetServices() - A new protected method
getExceptionClass()was introduced to return the exception class to throw from this factory when necessary
Url
The Url component has been moved to the Mvc namespace. more
Validation
The Validation component has been moved to the Filter namespace. more
Version
The Version component has been moved to the Support namespace. more
Volt
Since the tag service has changed from Phalcon\Tag to Phalcon\Html\TagFactory several helper methods used in Volt have changed also. The biggest change is the form() helper in Volt.
If you wish to keep your Volt code the way it is, without changing method signatures, you will have to rename your form() calls to formLegacy(). formLegacy() will use the Phalcon\Tag component as before. However, if you wish to use the new Phalcon\Html\TagFactory component, you can keep the method call as is (i.e. form() but you will need to change the signature of the helper method. more…