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

  • Home
  • SEARCH
  • 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

I'm getting an error here that says I haven't defined a method, but it
i have a input tag which is non editable, but some times i need
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I have found this example on StackOverflow: var people = new List<Person> { new
I have a login.jsp page which contains a login form. Once logged in the
Let say I have the following desire, to simplify the IConvertible's to allow me

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.