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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:30:02+00:00 2026-06-09T17:30:02+00:00

I have classes, each with a date related member variable that always has the

  • 0

I have classes, each with a date related member variable that always has the same naming format – field_{$node->type}_date

For example, if I my node type was ‘car’, the date field would be named field_car_date

So I am looping over all my nodes and I want to access the date related field for each of them. However I am getting an error. Here’s the code

$date_field_key = 'field_' . $node->type . '_date';
if (isset($node->$date_field_key['und'][0]['value'])) {

I get an error because of the second line. The error is – Illegal string offset 'und'
The date related variable is an array and it does have an element with the key ‘und’. If I write out the line explicitly – $node->field_car_date['und'][0]['value'] – it works fine. It’s just when I dynamically create the field name that I get this problem.

Any solution for this, is my syntax incorrect?

  • 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-09T17:30:04+00:00Added an answer on June 9, 2026 at 5:30 pm

    You need to surround you key value in {} because it’s a dynamically-assigned variable.

    In your second line, you have $node->$date_field_key['und'][0]['value'] where you should have:

    $node->{$date_field_key}['und'][0]['value']
    

    Notice the {} surrounding the date_field_key

    Good luck!

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

Sidebar

Related Questions

The situation: I have multiple classes that should each hold a variable with a
I have two classes that refer to each other, but obviously the compiler complains.
I'm using Apache BCEL to dynamically create java classes that will each have its
I have several controllers that take an instance of different classes each (Email, Call,
We have a base product that has bespoke development for each client that extends
I have several classes each containing several methods annotated with @Test . The classes
I have multiple classes in multiple dll's and each dll's may include other. I
I have a header menu and try to define different CSS classes for each
Is it a good practice to have multiple XXX : DbContext classes for each
How do I do forward declarations in Java? I have two classes, each needs

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.