PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 9, 2022

[FIXED] Using XmlReader with Yii - Class 'backend\components\XMLReader' not found

 January 09, 2022     php, xmlreader, yii, yii2     No comments   

Issue

I have this error:

PHP Fatal Error – yii\base\ErrorException Class 'backend\components\XMLReader' not found.

I'm working with the framework Yii and want to use XMLReader inside a component.

<?php 

namespace backend\components;

class XMLRead {

    public function parse() {
        // Instanciation de la classe XMLReader
        try {
            $xml = new XMLReader();
        } catch (Exception $e) {
            $e->getMessage();
        } 
    } 
} 

Solution

That is because you're using XMLReader class inside of backend\components namespace so XMLReader is interpreted as backend\components\XMLReader. You should either use leading backslash to indicate that class from global namespace should be used:

$xml = new \XMLReader();

Or import this class using use statement in head of your file:

<?php 

namespace backend\components;

use XMLReader;

class XMLRead {

    public function parse() {
        // Instanciation de la classe XMLReader
        try {
            $xml = new XMLReader();
        } catch (Exception $e) {
            $e->getMessage();
        } 
    } 
} 

You can read more about namespaces in documentation.



Answered By - rob006
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing