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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:31:47+00:00 2026-06-01T00:31:47+00:00

In the building process of an array I’m trying to call a function, checkIfNodeExists()

  • 0

In the building process of an array I’m trying to call a function, checkIfNodeExists(). PHP executes this function and gives me the expected result but he still gives me a “Notice”, and I don’t want any kind of errors in my code.

function checkIfNodeExists($input) {
   if (isset($input)) {
      return (string) $input;
   } else {
      return 'null';
   }
}

$array['sections'][] = array (
   'ident'       =>  $section->attributes()->ident,
   'title'       =>  $section->attributes()->title,
   'objective'   =>  checkIfNodeExists($section->objectives->material->mattext)
);

Notice: Trying to get property of non-object in /var/www/OLAT_Connection/QTI-XML-Parser.php on line xx

Now, if I check if “objective” exists OUTSIDE the array, PHP doesn’t give me a notice. But this results in more lines of code because I have to work with an extra variabele and more IF-structures and so on…

Is there any other possibility without adding too much lines of extra code?

  • 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-06-01T00:31:49+00:00Added an answer on June 1, 2026 at 12:31 am

    It seems that $section->objectives->material->mattext is not properly defined. I would start looking there to see if you have errors in the initialisation of the object.

    It would be better if you posted more code up so we can see what exactly is going on in this script.

    The solution may require more code (albeit unlikely in this case), this is by no means a bad thing. Less code is not necessarily better or more efficient! Obviously it goes without saying that fewer lines of code will (most of the time) execute faster, but this does not make it more secure or efficient

    UPDATE

    You may be able to simply do this instead of calling another function:

    'objective' => isset($section->objectives->material->mattext) ? (string)$section->objectives->material->mattext : null
    

    I have not tested this and cannot remember whether you can place conditional statements inline, so cannot be sure whether it will work but if it does then this will be more efficient, and it is less code!

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

Sidebar

Related Questions

I'm in the process of building a site with CodeIgniter. This is the 1st
I am currently working on a building community website in PHP. This contains forms
I'm trying to automate the building process for a certain open source project. It
I am dynamically building an array of objects using a process that boils down
I'm building a little sequencer like this one , but want to use HTML/JavaScript
I am trying to build a hierarchical array in PHP, from relational database contents
What is Eclipse doing when building workspace process is running? Can i disable it
During the process of building software applications, you would start testing what you have
I'm in the process of building a support page for my pre application. I'm
We're in the process of building a MOSS site and one of the 3rd

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.