menu

arrow_back Why are local to the function the array is not left with a stack?

by
0 votes
After C/C++ my brain is boiling from this. Why? How? Just read about scope in PHP, they do exist. Says that variables with local scope are destroyed when you exit it, as it should be. In the next Chapter, I can see IT.
5b7bfbea341a2167217073.png

PS: it is Written that arrays and objects are passed by reference.

7 Comments

Yegor Marchuk ,
in the book, the authors kotěra and Simdianov.

there are 136 (like) the page "links"

your listing with 243 pages
Yegor Marchuk like that :)
Nick Sdk i.e. I so understood that PHP in all "objects" (in the broad sense) are passed by value, I want the link -- use &, right?
php.net/manual/ru/language.types.array.php
Please note that when you assign an array always involves value copying. To copy an array by reference, you need to use the reference operator.
Nick Sdk hmm... the Author clearly lied to me by writing back or I misunderstood something. It said that in older versions of PHP passing arrays and objects produced in value than many were dissatisfied, and that the new version fixed the jamb. Something like that.
Nick Sdk in the textbook , the authors kotěra and Simdianov.
Says that variables with local scope are destroyed when you exit it, as it should be.

Well, Yes, in memory variable $aggage shouldn't be
at $updatepalette the contents of $arr, but not a reference to $arr
and references in PHP are a bit "other"
php.net/manual/ru/language.references.whatdo.php
php.net/manual/ru/language.references.pass.php

PS: it is Written that arrays and objects are passed by reference.

this is where and in what context? :)

1 Answer

by
1 vote
if you're talking about the size of the used memory it is not cleared immediately, and works scavenger hunt, how often it is run you can specify like php.ini for manual reset you can try gc_collect_cycles . In practice, very rare feature, is famous only in tests, there is useful to manually start under certain conditions

2 Comments

Just the author of the book confused me and I decided that arrays and objects are passed by reference by default.
Yegor Marchuk the kind of arrays are copied, and objects by reference, as only references to objects remain marked for deletion after the garbage man all the blows. Arrays and variables need to unset or at least in null. But again rare, because with the new query, all the memory will be clean, like before only had problems with open files and connections, do not know now. So the link to give variables (arrays) then you need to use &