php-internals

Where is the source code for strlen() function in PHP?

Deadly 提交于 2020-04-06 08:50:37
问题 I was looking through php-src/Zend/zend_API.c and couldn't find the source code for the strlen() function in PHP anywhere. Grepping through the code base didn't really help as it's littered with libc strlen everywhere. Googling doesn't much help either. I tried using the Vulcan Logic Dumper extension to inspect what's going on under the hood. I tried the following code as a test: <?php strlen("foo"); strpos("foo", "f"); This is what I got: Finding entry points Branch analysis from position: 0

PHP Internals: How does TSRMLS_FETCH Work?

人盡茶涼 提交于 2020-02-24 00:42:12
问题 How does the PHP Internals TSRMLS_FETCH macro do its job? Per the PHP Manual While developing extensions, build errors that contain "tsrm_ls is undefined" or errors to that effect stem from the fact that TSRMLS is undefined in the current scope, to fix this, declare the function to accept TSRMLS with the appropriate macro, if the prototype of the function in question cannot be changed, you must call TSRMLS_FETCH within the function body. I understand that declaring the function to accept

PHP Internals: How does TSRMLS_FETCH Work?

删除回忆录丶 提交于 2020-02-24 00:41:09
问题 How does the PHP Internals TSRMLS_FETCH macro do its job? Per the PHP Manual While developing extensions, build errors that contain "tsrm_ls is undefined" or errors to that effect stem from the fact that TSRMLS is undefined in the current scope, to fix this, declare the function to accept TSRMLS with the appropriate macro, if the prototype of the function in question cannot be changed, you must call TSRMLS_FETCH within the function body. I understand that declaring the function to accept

PHP Internals: How does TSRMLS_FETCH Work?

天涯浪子 提交于 2020-02-24 00:40:02
问题 How does the PHP Internals TSRMLS_FETCH macro do its job? Per the PHP Manual While developing extensions, build errors that contain "tsrm_ls is undefined" or errors to that effect stem from the fact that TSRMLS is undefined in the current scope, to fix this, declare the function to accept TSRMLS with the appropriate macro, if the prototype of the function in question cannot be changed, you must call TSRMLS_FETCH within the function body. I understand that declaring the function to accept

Is there ever a need to use ampersand in front of an object?

两盒软妹~` 提交于 2020-01-11 05:15:48
问题 Since objects are passed by reference by default now, is there maybe some special case when &$obj would make sense? 回答1: Objects use a different reference mechanism. &$object is more a reference of a reference. You can't really compare them both. See Objects and references: A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP 5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which

Calling extension function in zend_eval_string

三世轮回 提交于 2020-01-07 05:45:12
问题 When i try use zend_eval_string (i make mini php extension), there are no extensions functions avaliable. There are also no errors reporting (if php code have fatal error program exit). What i must do to enable extension and show errors when it executes? I also found interesting value EG(no_extensions)=1; in zend_execute_API.c, but when i change this value to 0 problem not solving. I am newer of c++ and please, tell me how to solve this problem with example. Sorry for my bad English. 回答1:

Why is file_get_contents faster than memcache_get?

浪子不回头ぞ 提交于 2020-01-02 02:17:09
问题 I'm loading XML files from disk using file_get_contents, and as a test I find I can load a 156K file using file_get_contents() 1,000 times in 3.99 seconds. I've subclassed the part that does the loading and replaced it with a memcache layer, and on my dev machine find I can do 1000 loads of the same document in 4.54 seconds. I appreciate that file_get_contents() will do some caching, but it looks like it is actually faster than a well-known caching technique. On a single server, is the

Capturing (externally) the memory consumption of a given Callback

萝らか妹 提交于 2019-12-29 09:09:05
问题 The Problem Lets say I have this function: function hog($i = 1) // uses $i * 0.5 MiB, returns $i * 0.25 MiB { $s = str_repeat('a', $i * 1024 * 512); return substr($s, $i * 1024 * 256); } I would like to call it and be able to inspect the maximum amount of memory it uses. In other words: memory_get_function_peak_usage($callback); . Is this possible? What I Have Tried I'm using the following values as my non-monotonically increasing $i argument for hog() : $iterations = array_merge(range(0, 50,

PHP array syntax/operator?

China☆狼群 提交于 2019-12-24 05:58:42
问题 When writing the syntax for an associative array in PHP we do the following $a = array('foo' => 'bar'); I am curious of the relationship of the => syntax, or possibly operator. Does this relate to some kind of reference used in the hash table in ZE, or some kind of subsequent right shift or reference used in C ? I guess I am just wondering the true underlying purpose of this syntax, how it relates to ZE and/or php extensions used to handle arrays, how it possibly relates to the written

how to access a variable from a class using php extension?

Deadly 提交于 2019-12-24 03:30:56
问题 I am working in c++ under ubuntu. I have the following example: [car.h] #ifndef VEHICLES_CAR_H #define VEHICLES_CAR_H // A very simple car class class Car { public: Car(); void shift(int gear); bool accelerate(); void brake(); int getCurrentSpeed(); int getCurrentGear(); public: int maxGear; int currentGear; int speed; }; #endif /* VEHICLES_CAR_H * / [car.cc] #include "car.hpp" #include "car2.hpp" #include "car2.cc" #include "car3.h" #include "car3.cc" #include <stdio.h> #include <iostream>