How to use the pointer concept in php?

Asked

Viewed 4,892 times

3

I’m learning about pointer in C language and I already know how to use it. I believe the way to use php pointer is the same in C. But how do I declare php pointer?

  • In php you can call references, but it is very difficult to see a post about it, http://www.vivaolinux.com.br/artigo/Referencias-ponteiros-em-PHP

  • It is important to note that there is no PHP pointer concept. At least not in the language so the programmer can use. As already stated in the reply, there are only references. Of course, PHP uses pointers to perform its activities but this is opaque. Pointer is something far more powerful than reference and consequently more complex and insecure if not properly manipulated.

1 answer

5


In PHP it can be called both pointers and references.

References, in PHP, means accessing the same variable content through several names. But it is common to erroneously hear the expression "use of pointers" in PHP, which in turn is not even close to the pointers in C: we have nicknames in PHP in a symbolic table (in C memory address).

<?php
  $a = &$b;
  // aqui $a e $b apontam para a mesma variável. 
?>

Soon $a and $b are completely equal here, but not because $a is pointing to $b or vice versa, but because $a and $b point to the same place.

The same syntax can be used with functions that return references and with the new operator (starting with PHP 4.0.4):

Source: http://www.vivaolinux.com.br/artigo/Referencias-ou-ponteiros-em-PHP?pagina=1

You can access the original POST on the site Viva o Linux and learn more about the subject. http://www.vivaolinux.com.br/artigo/Referencias-ou-ponteiros-em-PHP?pagina=1

  • *Long live The Linux..

  • 1

    Thanks Zebradomal, you could have done the most correction I’ve ever done.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.