We help IT Professionals succeed at work.

Why is PHP Storm giving me an undefined constant error?

burnedfaceless
on
714 Views
Last Modified: 2017-03-16
I am outlining chapter 3 of PHP Objects, Patterns, and Practice. What an incredible book.

PHP Storm is giving me the error of undefined constant simple xml and undefined function load file.

I want to be able to open this file in a browser (I'm doing one file a chapter with comments for notes). I haven't worked with XML and don't understand what is going on here.

Would someone please explain what is going on, but more importantly how to get it to load in a browser? Should I comment that line out?

//listing 03.14                                                                                                      
                                                                                                                     
/*sample xml                                                                                                         
<settings>                                                                                                           
  <resolvedomains>false</resolvedomains>                                                                             
</settings>                                                                                                          
*/                                                                                                                   
                                                                                                                     
//listing 03.15                                                                                                      
                                                                                                                     
class AddressManager                                                                                                 
{                                                                                                                    
    private $addresses = ["209.131.36.159", "216.58.213.174"];                                                       
    public function outputAddresses($resolve) {                                                                      
        foreach ($this->addresses as $address) {                                                                     
            print $address;                                                                                          
            if ($resolve) { //here is PHP making a judgement call to answer "TRUE" in an interaction with a string   
                print " (".gethostbyaddr($address).")";                                                              
            }                                                                                                        
        }                                                                                                            
                                                                                                                     
    }                                                                                                                
}                                                                                                                    
                                                                                                                     
   //listing 03.16                                                                                                   
                                                                                                                     
    $settings = simplexml:load_file(__DIR__."/resolve.xml");                                                         
    $manager = new AddressManager();                                                                                 
    $manager->outputAddresses((string)$settings->resolvedomains);                                                    

Open in new window

Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

Commented:
I think line 27 should be simplexml_load_file instead of simplexml:load_file.

Is the part captioned /*sample xml the test data?
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thanks Ray
Most Valuable Expert 2011
Author of the Year 2014

Commented:
10-4.  Hope it helped!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions