View Single Post
Old 05-07-2009, 10:19 AM   #20 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

I was under the impression that PHP's references functioned more like an alias (like a reference in C++) rather than a pointer, in other words they don't point to a memory location but are an alternative name for the target (think of it as a symlink), they more or less achieve the same but are different in terms of what you can do with them, you cant re-seat a reference as you can a pointer (in C++ anyway), you can't have a null reference whereas you can have a null pointer also you can't perform pointer arithmetic on references (which some would consider to be a good thing).

In terms of PHP however, you won't really need an in-depth knowledge of the differences between the too, they will both provide more or less the same functionality (in any case you can't directly fiddle with the memory in PHP like you can in C as its interpreted not compiled).

Just for the sake of illustration, heres a C++ pointer:
c++ Code:
#include <iostream>
using namespace std;

int main()
{
    unsigned short int age = 21;
    unsigned short int * pAge = 0;
    pAge =& age;

    cout << "Age: " << age << "pointer age: " << *pAge << endl;

    *pAge = 25;

    cout << "Age: " << age << "pointer age: " << *pAge << endl;
   
    age = 22;

    cout << "Age: " << age << "pointer age: " << *pAge << endl;

    return 0;
}

and a C++ reference:
c++ Code:
#include <iostream>
using namespace std;

int main()
{
    unsigned short int age = 21;
    unsigned short int&  rAge = age;
   
    cout << "Age: " << age << "ref age: " << rAge << endl;
   
    age = 25;

    cout << "Age: " << age << "ref age: " << rAge << endl;

    rAge = 22;

    cout << "Age: " << age << "ref age: " << rAge << endl;
   
    return 0;
}
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 05-07-2009 at 12:40 PM.
sketchMedia is offline  
Reply With Quote