How to override a Zend class?

There is no "local code pool override" mechanism anymore. Instead you can use preferences in di.xml for any class that is instantiated by the Magento object manager, i.e. used via Dependency Injection in Magento classes. This is the equivalent to a class rewrite in Magento 1.

But for classes like Zend_Date where this is not the case, this is not possible.

However you could create a composer package that loads your own Zend_Date class before the real one is loaded via autoloading:

composer.json

{
    "name": "your/custom-date",
    "autoload": {
      "files": ["src/lib/Zend/Date.php"]
    }
}

src/lib/Zend/Date.php

class Zend_Date
{
    ...
}

Edit: After you edited a composer.json file, run composer dump-autoload to update the autoloader.


From my experience, we shouldn't try to override a Zend class on this way. We should create a new class, this class will extends from Zend_Date. And then, try to override some Zend Date methods in your class as you want.