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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:17:22+00:00 2026-06-05T23:17:22+00:00

I received the error while trying to display some variable like so: echo id

  • 0

I received the error while trying to display some variable like so:

echo "id is $url->model->id";

The problem seems to be that echo only likes simple variables to be displayed in this way (like $id or $obj->id).

class url {
    public function  __construct($url_path) {
        $this->model = new url_model($url_path);
    }
}

class url_model {
    public function  __construct($url_path) {
        $this->id = 1;
    }
}

and then

$url = new url();
echo "id is $url->model->id"; // does not work

$t = $url->model->id;
echo "id is $t";  //works

$t = $url->model;
echo "id is $t->id";  //works

echo "id is {$url->model->id}"; //works. This is the same syntax used to display array elements in php manual.

//php manual example for arrays
echo "this is {$baz['value']}";

I don’t know why it works, I just guessed the syntax.

In php manual it doesn’t say how to use echo "..." for objects. Also there is some strange behavior: echo on simple vars, works; echo on simple property of an object works; echo on simple property of an object that is inside another object does not work.

Is this echo "id is {$url->model->id}"; the right way? Is there a simpler way?

  • 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-05T23:17:26+00:00Added an answer on June 5, 2026 at 11:17 pm

    "{$var}" is the universal string variable interpolation syntax. There are some syntax shortcuts known as simple syntax for things like one-dimensional arrays:

    echo "$arr[foo]";
    

    This does not work for multi-dimensional arrays though, e.g. "$arr[foo][bar]". It’s simply a hardcoded special case. The same is true for objects. "$obj->foo" is a hardcoded special case that works, while more complex cases will have to be handled by the complex "{$obj->foo->bar}" syntax.

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

Sidebar

Related Questions

I am received the following error while trying to implement a C# extension function
I received the following error while trying to login to a secured directory. As
While deploying my application, I got the error message: Thread 1:Program received signal: EXC_BAD_ACCESS.
I am trying to parse an XMl document that i received into a string
I am trying to resolve Fatal Error in MPI_Irecv: Aborting Job and received mixed
I have the following error while trying to start my node app: TypeError: Cannot
While trying to implement some jQuery UI Tabs using AJAX I keep running into
While trying to make a map in Scala, I receive the following error message:
I receive the following error in Microsoft SQL Server Report Builder Error While generating
While running the code I've included below I receive the error EntityCommandExecutionException was unhandled

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.