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
2
votes
3 answers

Capturing (externally) the memory consumption of a given Callback

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…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
2
votes
0 answers

Linking Lame.h with PHP extension

I'm trying to develop my first php extension. It uses Lame , so I've installed liblame-dev lame.h is located at /usr/include/lame/ In my config.m4 LIBNAME=lame PHP_ADD_LIBRARY($LIBNAME) It builds, but something goes wrong at apache startup …
sl4mmer
  • 381
  • 1
  • 13
2
votes
1 answer

zend engine return object reference

In php, it is valid to write something like this: How can I do this inside zend engine? I want a method to execute some operations, then return the class instance…
Wanderson Silva
  • 1,179
  • 1
  • 17
  • 35
1
vote
1 answer

Why C.O.W does not take place when ' writing to a property ' / ' injecting a property into an object ' of class?

class a { public $test="msg1"; } $t1 = new a; echo "echo1: After Instantiation :
"; xdebug_debug_zval('t1');echo "

"; $t2 = $t1; echo 'echo2: After assigning $t1 to $t2 :
'; xdebug_debug_zval('t2');echo…
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81
1
vote
1 answer

Log the REQUEST_URI variable when php is set to log to syslog

This is the source code of php_log_err. I would like to modify it to be able to log the variable _SERVER["REQUEST_URI"] /* {{{ php_log_err */ PHPAPI void php_log_err(char *log_message TSRMLS_DC) { FILE *log_file; char…
PiX
  • 9,705
  • 4
  • 19
  • 11
1
vote
1 answer

When does a 'symbol' / 'variable name' get created in PHP?

This is my setting: display_startup_errors = on display_errors = On error_reporting = E_ALL | E_STRICT //code1: $a = "abcd"; xdebug_debug_zval('a'); The above line of code would create a zval container and associate it with the symbol a'. And…
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81
1
vote
1 answer

Zend extension, get arguments of echo?

We have made a Zend extension which we want to write the addresses of the zval's echo is supposed to write out, but we cannot figure how to receive them because we have noticed that there is difference between echo "test"; and $a = "test"; echo…
Torben Pi Jensen
  • 850
  • 9
  • 27
1
vote
0 answers

Are PHP zvals mutable?

I've been reading about memory management in PHP and learned that variables in PHP copy the reference to zvals as long as you don't do a write operation (copy on write…
tweekz
  • 187
  • 1
  • 9
1
vote
1 answer

php extension how to return a string from a method?

I have in [example.cc] a method : std::string Car::accelerate (std::string n) { cout<
sunset
  • 1,359
  • 5
  • 22
  • 35
1
vote
1 answer

Array as class member and refcounting

There is something that confuses me. Let there be a class member Foo::$bar, which has to be initialized as an empty array in the constructor. If I do that (via zend_update_property), its refcount is increased (from 1, which it gets after alloc +…
Flavius
  • 13,566
  • 13
  • 80
  • 126
1
vote
0 answers

How to create a php extension function with a return type-hint plus annotation

I'm trying to fix some php 8.1 deprecation notices in a PHP extension, which I believe involves either adding return type-hints (where possible, whilst maintaining some backwards-compatibility to php7.0), or adding a #[\ReturnTypeWillChange]…
Brett McBride
  • 192
  • 1
  • 6
1
vote
1 answer

How do I add a new opcode to PHP?

Searching for it I found this blog post: https://www.npopov.com/2017/04/14/PHP-7-Virtual-machine.html Does it cover "everything" needed to add a new opcode, or all the places I'd need to touch in the engine? Or is it better to just start grepping in…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
1
vote
2 answers

PHP array syntax/operator?

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…
grep
  • 3,986
  • 7
  • 45
  • 67
1
vote
1 answer

What are the limits on session names in PHP?

The PHP docs on session_name() say: It should contain only alphanumeric characters; it should be short and descriptive (i.e. for users with enabled cookie warnings). ... The session name can't consist of digits only, at least one letter must be…
Synchro
  • 35,538
  • 15
  • 81
  • 104
1
vote
1 answer

How can I overwrite an internal Zend function with a PHP extension?

Hope this isn't too silly a question to ask. I'm fairly new to C and PHP internals but looking to learn more about them. I've recently began looking into development of PHP extensions. I'm trying to overwrite an internal function to perform some…
fufyayokku
  • 11
  • 1