php-internals

How does array_keys do the search for value?

我只是一个虾纸丫 提交于 2019-12-05 21:15:38
How does PHP array_keys do the search for value? Example: $array2 = array("xyz", "xyz", "abc", "abc", "xyz", "xyz", "text", "abc", "text"); print_r(array_keys($array2,"abc")); Since they are key,value pairs. I am guessing PHP to do a search based on hash rather than iterate through each of the key-pairs in the array. Any 'clarity thoughts' on this? Question inspired by this question: How to get the keys of empty elements in an array if the corresponding element in a similar-sized array is a number (without iteration)? In the php source, they iterate through each key and value, one by one.

Why is Importing a PHP Function into the Current Namespace Unsupported

可紊 提交于 2019-12-05 11:17:14
According to the PHP documentation PHP namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. Note that importing a function or constant is not supported. Does anyone know the historical or technical context of why importing a function or constant is unsupported? I contacted Jochem Maas (the author of this five year old RFC ), and while he was hesitant to pin point a single reason (understandably, as he isn't currently deeply involved with the namespace system), his three factors were Class name collisions were

__memcpy_sse2_unaligned - what does this mean in detail?

烂漫一生 提交于 2019-12-05 11:13:21
问题 While working on my compiler I got this error: Program received signal SIGSEGV, Segmentation fault. __memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:33 How do I get details of what went wrong here? I know from the backtrace it's a memcpy line that causes it, but how do I see how the memory is aligned? And how do I know how it should be aligned? The project is a compiler with an LLVM back-end using the Zend/PHP runtime with the OCaml garbage collector, so there

Why does foreach increase refcount by 2 instead of 1?

不羁岁月 提交于 2019-12-04 12:23:50
问题 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 showing a different result: $array = array(0, 1, 2); xdebug_debug_zval('array'); // refcount=1, is_ref=0 // so far so good foreach ($array as $key => $value) { xdebug_debug_zval('array'); // refcount=3, is_ref=0 } // why is refcount 3 instead of 2? Just

Where to find the “low memory” and “free CPU cycles” calls triggering garbage collection on unset()?

北城以北 提交于 2019-12-04 04:49:01
I often find references to the following quote being used when explaining that a PHP unset() doesn't trigger "garbage collection" immediately, but only when it sees fit (emphasis mine): unset() does just what it's name says - unset a variable. It does not force immediate memory freeing. PHP's garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren't needed anyway, or as late as before the script would run out of memory , whatever occurs first. If you are doing $whatever = null; then you are rewriting variable's data. You might get memory freed / shrunk

__memcpy_sse2_unaligned - what does this mean in detail?

风格不统一 提交于 2019-12-04 00:36:57
While working on my compiler I got this error: Program received signal SIGSEGV, Segmentation fault. __memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:33 How do I get details of what went wrong here? I know from the backtrace it's a memcpy line that causes it, but how do I see how the memory is aligned? And how do I know how it should be aligned? The project is a compiler with an LLVM back-end using the Zend/PHP runtime with the OCaml garbage collector, so there's is a lot of things that can go wrong. I suspect this line being part of the problem: zend_string

Why can't you inherit from a not-yet-defined class which inherits from a not-yet-defined class?

烈酒焚心 提交于 2019-12-03 11:36:23
问题 I research about class compilation, it's sequence, and logic. If I declare a class before a simple parent: class First extends Second{} class Second{} This will work OK. See live example across PHP versions. But if the parent class also has some not-yet-declared parents (extends or implements), as in this example: class First extends Second{} class Second extends Third{} class Third{} I will have an error: Fatal error: Class 'Second' not found ... See live example across PHP versions. So, why

Why does foreach increase refcount by 2 instead of 1?

心已入冬 提交于 2019-12-03 08:58:43
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 showing a different result: $array = array(0, 1, 2); xdebug_debug_zval('array'); // refcount=1, is_ref=0 // so far so good foreach ($array as $key => $value) { xdebug_debug_zval('array'); // refcount=3, is_ref=0 } // why is refcount 3 instead of 2? Just by looking at the code, we can see at most two array variables. Why is refcount 3 ? Why isn't refcount

What is exactly happening when instantiating with 'new'?

爱⌒轻易说出口 提交于 2019-12-03 01:50:16
Let's consider the following code: class a { public $var1; function disp(){ echo $this->var1; } } $obj1 = new a; echo '<br/>After instantiation into $obj1:<br/>'; xdebug_debug_zval('obj1'); $obj1->var1 = "Hello "; echo '<br/><br/>After assigning "Hello" to $obj->var1:<br/>'; $obj1->disp(); echo "<br/><br/>"; xdebug_debug_zval('obj1'); The output: After instantiation into $obj1: obj1: (refcount=1, is_ref=0)=class a { public $var1 = (refcount=2, is_ref=0)=NULL } After assigning "Hello" to $obj->var1: Hello obj1: (refcount=1, is_ref=0)=class a { public $var1 = (refcount=1, is_ref=0)='Hello ' }

Why can't you inherit from a not-yet-defined class which inherits from a not-yet-defined class?

喜夏-厌秋 提交于 2019-12-03 01:11:29
I research about class compilation, it's sequence, and logic. If I declare a class before a simple parent: class First extends Second{} class Second{} This will work OK. See live example across PHP versions. But if the parent class also has some not-yet-declared parents (extends or implements), as in this example: class First extends Second{} class Second extends Third{} class Third{} I will have an error: Fatal error: Class 'Second' not found ... See live example across PHP versions. So, why in the second example it can't find Second class? Maybe php can't compile this class because it need