Questions tagged [php-internals]

How the PHP programming language works underneath, and questions about the underlying C code.

PHP Internals

Tag purpose

The purpose of the tag is to indicate a question about the internals of PHP. Possible questions could be about how references counting or copy on write. E.g. When you want to know what happens under the hood while doing things in PHP. It can also be applied to questions in the tag that deal with extending PHP at the core. This tag should also be used for any questions about the Zend Engine powering PHP.


External Links

269 questions
6
votes
1 answer

Does PHP optimize function arguments of array type, not explicitly passed by reference, when they are not modified?

Would the PHP engine optimize the second example to pass the $arr by reference? function test1(array &$arr) { $arr[] = 123; echo $arr[0]; } function test2(array $arr) { echo $arr[0]; }
marsgpl
  • 552
  • 2
  • 12
6
votes
1 answer

Why doesn't PHP use internal smart string for strings?

PHP have an internal data-structure called smart string (smart_str?), where they store both length and buffer size. That is, more memory than the length of the string is allocated to improve concatenation performance. Why isn't this data-structure…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
6
votes
1 answer

PHP use statement for namespace

Maybe this is weird question, but I can't work it out what happens internally in php when you write: use garcha\path\class; I'm not asking about purpose of namespaces, but about that statement itself, even it does not allocate any memory, I mean,…
George G
  • 7,443
  • 12
  • 45
  • 59
6
votes
6 answers

Increasing array elements while in foreach loop in php?

Consider the code below: $val) { print "key=>$key\n"; if(!isset($arr['a'])) $arr['a'] = 'apple'; } ?> It is not displaying 'a'. How foreach works with hash-table(array), to…
Tarun Chabarwal
  • 332
  • 4
  • 15
6
votes
1 answer

Why does foreach increase refcount by 2 instead of 1?

NikiC stated in another thread: Right before [a foreach] iteration the $array is "soft copied" for use in foreach. This means that no actual copy is done, but only the refcount of the zval of $array is increased to 2. However, my test code is…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
6
votes
1 answer

how to convert zval to vector for php extension?

i'm writing a php extension for my c++ library which is defined something like this: bool getPids(map pidsMap, vector ids); now, i'm writing a php wrapper for above function like this. ZEND_METHOD(myFInfo, get_pids) { …
Prod Tester
  • 253
  • 2
  • 5
  • 16
5
votes
1 answer

How does the PHP MongoDB Driver's Cursor buffer a result set?

When queries are made to mongodb, how does it's cursor deal with the result set in memory? Does the cursor retrieve all documents which match the query, at once? or does it retrieve 1 document at a time? or are they buffered? or is there a…
Jim Rubenstein
  • 6,836
  • 4
  • 36
  • 54
5
votes
2 answers

Which PHP functions are affected by allow_url_fopen?

In PHP, the allow_url_fopen flag controls whether or not remote URLs can be used by various file system functions, in order to access remote files. It is recommended security best practice nowadays to disable this option, as it is a potential attack…
HappyDog
  • 1,230
  • 1
  • 18
  • 45
5
votes
4 answers

How to understand the 3 lines of c code?

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) { return; } Especially what's ZEND_NUM_ARGS() TSRMLS_CC doing?
ccr
  • 81
  • 1
5
votes
1 answer

What is exactly a zend extension?

if you look at this documentation, the first parameter returns only Zend extensions. What is exactly a Zend extension, as compared to a PHP ("simple") extension?
Bob5421
  • 7,757
  • 14
  • 81
  • 175
5
votes
0 answers

PHP, Compile foreach and opline

I'm trying to figure out how a foreach statement is interpreted by PHP. That led me to use gdb while executing a dummy foreach script. I end up in zend_compile.c, in the zend_compile_foreach() function. I see the call to the macro ZEND_FE_FETCH_R…
JesusTheHun
  • 1,217
  • 1
  • 10
  • 19
5
votes
1 answer

Why does PHP allow passing a literal to a pass-by-reference parameter in one case but not others?

The function array_shift() takes one parameter by reference. Passing an array literal causes a fatal error: $ php -r 'var_export(array_shift(array("Test #0"));';echo Fatal error: Only variables can be passed by reference in Command line code on…
user3427070
  • 499
  • 5
  • 14
5
votes
0 answers

Why does accessing a null value in PHP as an array not generate a warning?

I was hit by a bug where a returned DB result was expected to be an array but due to a glitch in the SQL query in one instance the DB wrapper correctly returned null. Unfortunately the code did not expect that (=bug). However, I was surprised to see…
Nils
  • 189
  • 1
  • 14
5
votes
1 answer

Does PHP engine optimize anonymous functions within loops?

I have an array which stores multiple references to a single anonymous function: $fns = array(); //some code $fn = function(){ echo 'this is closure 12345... < 67890'; // etc etc.. }; for($x=12345; $x<67890; ++$x){ $fns[$x] = $fn; } As…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
5
votes
1 answer

Exactly what causes E_CORE_ERROR and E_CORE_WARNING?

PHP Manual states that E_CORE_ERROR are fatal errors that occur during PHP's initial startup: This is like an E_ERROR, except it is generated by the core of PHP. Also, it states that E_CORE_WARNING are warnings that occur during PHP's initial…
Pacerier
  • 86,231
  • 106
  • 366
  • 634