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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:02:05+00:00 2026-05-17T21:02:05+00:00

I haven’t done much programing in many languages, but I know in C(++), you

  • 0

I haven’t done much programing in many languages, but I know in C(++), you have to declare a variable type (int,char,etc).

In PHP you, of course, don’t have to do that. You can start with $str = "something"; then later $str = array("something" => "smells"); and she is happy.

How does PHP compile? How does it know what the variable type is going to be? Does it even care?

This question has no relevance to anything I am doing. I am just curious.

EDIT.

I need to clarify this question a little bit.

In C, if I say:

int y;

It reserves x amount of bytes for y. If y overflows, bad news.

PHP doesn’t have this nature (at least I don’t think it does).

$i = "a number";
$i = 8;
$i = 1000000000000000000;

It’s all the same to the language. How does it know how much to reserve? Or am I comparing Apples to Oranges? If I am going about this wrong, do you have any good topics that I can read to better understand?

  • 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-17T21:02:06+00:00Added an answer on May 17, 2026 at 9:02 pm

    Since you have C experience, consider a PHP variable to be like the following:

    typedef struct {
     int varType;
     void* data;
    } variable_t;
    

    when you create a new variable, it will create a variable_t, give it a type tag (lets say 1 for int, 2 for string), and store it in a list somewhere (by scope, reference by name). The actual contents will be stored in *data. When the variable is again accessed, the type can be determined from int varType, and the appropiate action taken on void* data, such as using it as an int or string.

    Imagine that the PHP snippet:

     $data = 12;
     $data2 = $data + 1;
     $data = "Hello";
    

    produces instructions like the following (pseudo-Cish):

    Line 1:
    variable_t* var = new_variable(TYPE_INT, data);
    store_variable("data", var);
    
    Line 2:
    variable_t* var = get_variable("data2");
    if (var->varType == TYPE_INT)
       int value = 1 + *(int*)var->data);
    else
       error("Can't add non int");
    var = new_variable(TYPE_INT, value);
    store_variable("data2", var);
    
    Line 3:
    variable_t* var = get_variable("data");
    if (var)
      destroy_variable(var);
    // Do like line 1, but for TYPE_STRING
    

    This type of augmented data works in bytecoded, compiled, or direct interpreted languages.

    There are more details in regards to different virtual machine implementations (local allocation, heap allocation, register VMs, etc). If you actually want to understand how virtual machines work, the best reference is Lua. Very clean language, very clean bytecode, and very clean virtual machine. PHP is probably the last implementation you should look at.

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

Sidebar

Related Questions

Haven't done as much of Javascript as I should have done. I am trying
haven't used regex replaces much and am not sure if how I have done
I haven't done too much XML parsing in the past, I have a page
I haven't used the STL much before, but I started to on this huffman
I haven't found any documentation on this or seen this done before, but is
I haven't worked with SQL Reporting much, however I have been trying to get
Haven't seen anything, but I have seen that you can create albums in the
I haven't done any C++ in a while, but decided to finish a big
I haven't delved much into comet programming, but it interests me and I want
Haven't seen many Geneva related questions yet, I have posted this question in the

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.