When trying to boost code quality, I frequently encounter errors like "The use of function file_exists() is forbidden" when trying to use PHP file functions. This for instance happens with the Magento ECG coding standard and also with the Magicento plugin for PhpStorm. However, I'm kind of lost on what I should use instead. The ZF-1 documentation is not listing any wrapper like Zend_File so there must be something I'm overlooking ...

Anyone has an idea?


4 Answers 4


Try Zend_Validate_File_Exists




$validator = new Zend_Validate_File_Exists();

    echo "true";
} else {
    echo "false"; 

I've come to the understanding that my original question actually deals with quite a few of subquestions: Each time the ECG group complains about a certain PHP function that should be used, it is kind of a hassle to find out which wrapper class should be used instead: In this thread, Varien_Io_File and Zend_Validate_File_Exists were already mentioned, and that actually leads to a search for the right class throughout the system (or actually mostly the /lib folder). I'm fine with that though.

  • Sure, but whenever there is a conflict between Varien and Zend, I'd go with Varien, since that is the lib Magento prefers over Zend, and whenever needed, it already extends Zend.
    – Prateek
    Commented Sep 29, 2015 at 11:42

In addition to Renon Stewart answer you can also use ...

  1. Varien_Io_File

    $io = new Varien_Io_File();
    if (!$io->fileExists($filePath)) {
  2. there is also an !file_exists mehtod:

    $validatorNot = new Zend_Validate_File_NotExists($path);
    if ($validatorNot->isValid($file)) {

I also have Magicento with PHP Storm (It's F&kng awesome !) but did not encounter so far, have to look at my Magicento settings. In magento 1.9.2 the function file_exists is used in 251 different places. And only 17 in /Mage/Core/ !

**If i counted correct, almost clean installation :-)

Nice question, i like these more than... "Why isn't this working ?" questions.

  • I agree with you that it is kind of weird that the call appears so many times in the Magento core itself. But the main point of the ECG standard (and others) is ofcourse that if "the framework" offers a wrapper for some kind of PHP function, you should use the wrapper instead of the PHP function. And "the framework" is for us third-party developers either the Magento core or Zend Framework. Commented Sep 29, 2015 at 10:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.