php-internals

PHP String Length Without strlen()

a 夏天 提交于 2019-12-23 17:07:28
问题 Just browsing over the latest release of the PHP coding standards, and something caught my eye: http://svn.php.net/viewvc/php/php-src/trunk/CODING_STANDARDS?revision=296679&view=markup Coding standard #4 states that "When writing functions that deal with strings, be sure to remember that PHP holds the length property of each string, and that it shouldn't be calculated with strlen()..." I've ALWAYS used strlen, and maybe it's just late, but how do you access the built-in length property of a

How does array_keys do the search for value?

二次信任 提交于 2019-12-22 09:48:56
问题 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

What is exactly happening when instantiating with 'new'?

喜夏-厌秋 提交于 2019-12-20 11:49:10
问题 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-

Compare PHP Arrays Using Memory References

笑着哭i 提交于 2019-12-18 16:55:10
问题 Is it possible to see if two array variables point to the same memory location? (they are the same array) 回答1: Actually, this can be done. Through a php extension. File: config.m4 PHP_ARG_ENABLE(test, whether to enable test Extension support, [ --enable-test Enable test ext support]) if test "$PHP_TEST" = "yes"; then AC_DEFINE(HAVE_TEST, 1, [Enable TEST Extension]) PHP_NEW_EXTENSION(test, test.c, $ext_shared) fi File: php_test.h #ifndef PHP_TEST_H #define PHP_TEST_H 1 #define PHP_TEST_EXT

Confusion about PHP 7 refcount

半城伤御伤魂 提交于 2019-12-18 12:33:14
问题 <?php $s = "foobar"; $t = $s; $u = $s; echo PHP_VERSION . "\n"; debug_zval_dump($s); xdebug_debug_zval('s'); Run in PHP 5.6.16 Run in PHP 7.0.2 I think the result (PHP 7) should be: string(6) "foobar" refcount(4) s: (refcount=3, is_ref=0)="foobar" I wonder what makes the difference? Need some explanation. Thanks a lot. ------ update ------ Nikita Popov's - PHP 7 – What changed internally? (P41) http://www.slideshare.net/nikita_ppv/php-7-what-changed-internally 回答1: In PHP 7 a zval can be

What's the Difference Between Extension and zend_extension in php.ini?

我们两清 提交于 2019-12-18 10:48:12
问题 When I installed Xdebug through pecl , it added the following line to my php.ini file. extension="xdebug.so" and everything I used worked. Until today. Today I was having trouble setting up Xdebug for interactive debugging. I couldn't get anything working until I changed the above to zend_extension="/usr/local/lib/php/extensions/xdebug.so" (Caveat: I think this is what got me working, but I'm not 100% sure) This raised the question in my mind. What's the difference in loading an extension via

How does PHP assign and free memory for variables?

核能气质少年 提交于 2019-12-18 02:43:19
问题 I was wondering when does PHP free the memory which is used for a variables for example function foo(){ $foo = 'data'; return $foo; // <- is the memory space for `$foo` emptied at this point? } is it slower than: function foo(){ return 'data'; } ? 回答1: Well, let's find out! <?php $checkpoints = array( 'start' => memory_get_usage() ); $checkpoints['before defining demo1'] = memory_get_usage(); function demo1() { $foo = 'data'; return $foo; } $checkpoints['after defining demo1'] = memory_get

Reading Zend Engine API code: What does ## (double hash) mean?

守給你的承諾、 提交于 2019-12-18 01:56:10
问题 Out of curiousity, I'm reading the Zend Engine API code and encountered quite a number of ## in their #define's. For example, at /usr/lib/php5/Zend/zend_API.h: #define ZEND_FN(name) zif_##name #define ZEND_MN(name) zim_##name What does the ## (double hash) symbols mean in these two lines? 回答1: The ## concatenates what's before the ## with what's after it. So in your example doing ZEND_FN(foo) would result in zif_foo 回答2: Echo RvV's answer. Be aware that when concatenating literal strings you

How are associative arrays implemented in PHP?

瘦欲@ 提交于 2019-12-17 07:24:08
问题 Can someone explain how PHP implements associative arrays? What underlying data structure does PHP use? Does PHP hash the key and store it in some kind of hash map? I am curious because I was wondering what the performance of associative arrays where when inserting and searching for keys. 回答1: It's a hash table. The type declaration and hashing function are here: http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_hash.h?view=markup There is a light weight array and a linked list within the

Getting Started with PHP Extension-Development [closed]

雨燕双飞 提交于 2019-12-17 07:15:17
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Please suggest help articles or tutorials about PHP "low" level С-modules programming interface. 回答1: Searching through my bookmarks, only links I found are those : Extension Writing Part I: Introduction to PHP and Zend Extension Writing Part II: Parameters, Arrays, and ZVALs Extension Writing Part II: