2

I have checking my Module`s Code using

--standard=MEQP2

that provide me some warnings magento coding standerd

How can i use the core function of php in Magento 2.3.1

4

You can use the Magento framework methods instead of core php functions(AFAIK for the security reasons Magento discouraged these types of functions)

For example,

      use Magento\Framework\Filesystem\Io\File;

        /** @var File */
        private $file;

        /**
         * @param File $file
         */
        public function __construct(File $file)
        {
            $this->file = $file;
        }

file_exist() can be

$this->file->fileExists($file);

unlink() can be

$this->file->rm($file)

mkdir() can be

$this->file->mkdir($dir)

`dirname() can be

$this->file->dirname($file)

file_put_contents() can be

$this->file->write($filename, $src, $mode)

Also, for The direct use of ObjectManager is discouraged you should inject necessary dependencies via constructor , you can read more about it from the Magento DevDocs

enter image description here

Last, getOrderOptions() method you wrote in for or foreach loop , so you need to check it is really needed to write this method in a loop or you can do something else.

  • this code is work for mini cart so i had get options of cart items in foreach loop there is any another solution for this – Bhavesh Prajapati Apr 24 at 12:45
  • 1
    please ask a new question for this with your code so someone can check , as from the current question it is only for core php function @phpdeveloper – Keyur Shah Apr 24 at 12:50
  • this other trikes are work for me to use php core functions pleas give me solution about 44 Function's nesting level (8) exceeds 5; consider refactoring the function – Bhavesh Prajapati Apr 24 at 12:50
  • which i use for is_dir() – Bhavesh Prajapati Apr 24 at 12:59
  • is_dir is not allowed how to resolve it – Bhavesh Prajapati Apr 25 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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