Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:15:48+00:00 2026-05-23T01:15:48+00:00

I’ve been messing around with simplexml_load_file() function which returns SimpleXMLElement and for learning purposes,

  • 0

I’ve been messing around with simplexml_load_file() function which returns SimpleXMLElement and for learning purposes, I tried the weather.gov restful services to bring some data and see how it works.

So basically this is what I did:

$xml = simplexml_load_file("http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdXMLclient.php?whichClient=NDFDgen&lat=38.99&lon=-77.01&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=&centerPointLat=&centerPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=&sector=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=time-series&begin=2004-01-01T00%3A00%3A00&end=2015-06-10T00%3A00%3A00&maxt=maxt&Submit=Submit");

var_dump($xml);

The link belong to weather.gov and a rest service.

And now my question comes:

When I dumped the variable something took my attention and I couldn’t find a way to describe it to myself.

Here is some piece of the dumped variable:

object(SimpleXMLElement)[1]
  public '@attributes' => 
    array
      'version' => string '1.0' (length=3)
  public 'head' => 
    object(SimpleXMLElement)[2]
      public 'product' => 
        object(SimpleXMLElement)[4]
          public '@attributes' => 
            array
              ...

When I saw public '@attributes' => array I thought I could reach the variable typing $xml->attributes['version'] but I was wrong since I learned this was the correct way $xml['version'] and I started wonder how it is possible since $xml became array here but this code also works fine after running the first code $xml->head->product->title which returns the value of the title element defined under head > product.

It looks like an indexers like in C#. Basically this is a valid code in c# below:

public int this[int index]    // Indexer declaration
{
    // get and set accessors
}

But I couldn’t think of a way which provides the same functionality in PHP classes.

Can somebody tell me how the ‘@attributes' is called in PHP, an indexer? And how to achieve this functionality in PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:15:49+00:00Added an answer on May 23, 2026 at 1:15 am

    Objects of classes that inherit from ArrayObject and/or implement ArrayAccess (which ArrayObject itself implements) can be accessed with indexers. Although SimpleXMLElement itself doesn’t implement either one (it’s probably an internal implementation), you can achieve the same functionality in your own classes using them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.