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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:42:52+00:00 2026-05-20T07:42:52+00:00

I am new to PHP (still) and keep learning. I often have to retrieve

  • 0

I am new to PHP (still) and keep learning.

I often have to retrieve a certain variable and access its properties.

<?php
      $id = $_REQUEST['id'];
      $user_info = get_userdata($id);

      echo('Username: '        . $user_info->user_login . "<br>");
      echo('User level: '      . $user_info->user_level . "<br>");
      echo('User ID: '         . $user_info->ID . "<br>");
      echo('First Name: '      . $user_info->user_firstname . "<br>");
      echo('Family Name: '     . $user_info->user_lastname . "<br>");
      echo('user_registered: ' . $user_info->user_registered . "<br>");
?>

I would prefer to once retrieve $user_info = get_userdata($id); and then use it when needed
in the same file but in different <?php?> blocks

<?php
    $id = $_REQUEST['id'];
    $user_info = get_userdata($id);
?>

<some HTML>

<?php echo $user_info->user_login; ?>

<some HTML>

<?php echo $user_info->user_login; ?>

But I suspect $user_info cannot be shared between blocks because it is not global.
What is usual practice for that?

  • 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-20T07:42:53+00:00Added an answer on May 20, 2026 at 7:42 am

    You’re putting too much meaning in the php code blocks.
    It’s not something that global.
    These blocks belong to the same PHP script. It’s just a neat way to output HTML, nothing more. You can substitute it with echoing the HTML and there will not be the slightest difference.

    The whole PHP script is being executed at once, not in iterations, as you probably picture this, thinking that PHP blocks are being executed server-side, then HTML blocks client-side, and then back to PHP blocks on the server side and so on. That’s wrong.
    The whole PHP script is being executed on the server side, resulting with pure HTML in the browser, and then dies.

    That’s why you can’t program both an HTML form and its handler in the same PHP script by just placing the latter one right after the former. You have to make another call to the server to make the handler work. It will be another call completely, another instance of the same script, knowing nothing of the previous call which is long dead already. And that’s another thing you have to know about PHP:

    PHP script execution is atomic. It’s not like a desktop application constantly running in your browser, or even a daemon with persistent connection to your desktop application. It’s more like a command-line utility – doing its job and exits. It runs discretely:

    1. a browser makes a call
    2. PHP wakes up, creates an HTML page, sends it to the browser and dies
    3. Browser renders that HTML and shows it to the user.
    4. User clicks a link
    5. a browser makes a call
    6. another PHP instance, knowing nothing of the previous call, wakes up and so on
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to php, but I am learning! I have a simple
I'm new to PHP and have installed on Linux to boot (also a newbie).
I have a PHP application that currently has 5k users and will keep increasing
I'm relatively new to PHP and still getting the hang of what's possible. So
Has anyone ever modified the post-new.php file in their WordPress installation? I want to
To put it simply i am a fairly new PHP coder and i was
We are in the startup build phase of a new PHP webapp that will
Rather new to php, so sorry if this seems stupid. I'm really copying a
Im new to PHP and I can't figure out what the rules are for
I'm new to PHP and I'm confused seeing some examples calling a function with

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.