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 7588423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:54:59+00:00 2026-05-30T19:54:59+00:00

I’m working on a project (simple XML CMS) just to learn some basic PHP.

  • 0

I’m working on a project (simple XML CMS) just to learn some basic PHP.

First I include a config.php file which contains information about the CMS, and then I include a route.php for the URL routing and after that I include a functions.php file which is pretty similar to the WordPress’ one (contains all the functions to for example load posts, tags, categories, etc.).

The structure looks like this:

<?php
    function latestProducts($amount = 6){
    }

    function products($search = FALSE, $query= '', $page = 1, $results = 5){
    }

    function getProductById($id){
    }

    function getProductTitleById($id){
    }

    function getProductByExcerpt($excerpt){
    }

    function getProductTitleByExcerpt($excerpt){
    }

    function getPost($id, $title, $description, $category, $excerpt = FALSE){
    }

    function getTitle(){
    }

    function breadcrumb($params, $first){
    }

    function pagination($page, $pages){
    }
?>

In config.php file I also use this code:

$xml = simplexml_load_file("products.xml") or die("The product XML file couldn't be loaded.");

But when I try to access $xml from within the functions I prepared in functions.php, I get a undefined variable notice. (I also tried placing the $xml variable inside the functions.php before the definition of the functions, but I got the same result.)

What is my mistake? I know it’s simple; I just can’t see clearly right now.

  • 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-30T19:55:00+00:00Added an answer on May 30, 2026 at 7:55 pm

    You have a scoping issue. The variables declared in the global scope aren’t visible inside your functions. The manual explains what you can do about it. An overview:

    • Import the variable from the global scope into the local scope of your function with global $xml; at the start of the function
    • Store the variable as a key of the global variables superglobal, i.e. $GLOBALS['xml']
    • Make the variable a static member of a class or create a singleton construction
    • Pass the variable as an argument to every function that needs it

    Note that when using a good OOP-style architecture these kind of problems can often be avoided, e.g. $xml would be a property of class instances that need direct access to the DOM object.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.