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
5
votes
1 answer

Why is Importing a PHP Function into the Current Namespace Unsupported

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…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
5
votes
1 answer

How to make ZEND_BEGIN_ARG_INFO_EX control number of arguments, passed to a PHP extension?

I'm developing a PHP extension, using C. So far I'm working on the proper validation of arguments, passed to the extension's function from PHP userspace. The macro ZEND_BEGIN_ARG_INFO_EX can be used to provide Zend Engine with information about the…
Andrey Tserkus
  • 3,644
  • 17
  • 24
4
votes
1 answer

How to overload functions from a PHP extension?

I've been going through some PHP extension tutorials, but I can't find any information about how to overload existing function. For example, I want to change the fopen() to something like PHP_FUNCTION(fopen) { if condition_is_true(condition) …
Vasisualiy
  • 750
  • 5
  • 19
4
votes
0 answers

PHP5 zval container vs PHP7 zval container. How references & variables are stored now?

I am following a tutorial & reading through some articles on how variables are stored in PHP using zval (zend value) container. Most of those articles seem to be following & getting information from the documentation on php.net doc. I got curious…
Fuze
  • 93
  • 6
4
votes
1 answer

Where is PHP echo implemented in the source?

You can lookup built-in functions by searching for e.g. PHPAPI(stream_copy_to_stream) and find the implementation in ext/standard/streamsfuncs.c. How to do that for a language construct like echo? I found it is associated with T_ECHO in…
cachius
  • 1,743
  • 1
  • 8
  • 21
4
votes
0 answers

What userland strings get automatically interned by PHP?

I was trying to get a better understanding of PHP's internal mechanisms of string interning - more specifically: What are the rules PHP uses to determine whether (or not) the string created in userland will be interned...? I see two…
Smuuf
  • 6,339
  • 3
  • 23
  • 35
4
votes
1 answer

Why does php allow invalid return type declerations it knows it can't allow?

As far as I can tell php has the ability to prevent a return type from being declared where it knows it's problematic. class Foo { public function __clone(): Baz { return new Baz; } } class Baz { } $foo = new Foo; $newFoo = clone…
emptyheap
  • 83
  • 6
4
votes
1 answer

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

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…
emptyheap
  • 83
  • 6
4
votes
3 answers

PHP's static member and instance member seems no different. Why PHP does so(Without warning)?

staticFunc(); // static This means in PHP static method…
reeze
  • 37
  • 1
  • 5
4
votes
1 answer

What is the actual memory cost of storing an integer?

lets say I just do this $arr = array(); for ($i = 0; $i < 10; $i++) $arr[] = $i; So I store 10 integers in an array. If the integer is a 32b one, the memory cost should be 40 bytes. Problem is, I didn't tell php that it is an integer so it either…
user81993
  • 6,167
  • 6
  • 32
  • 64
4
votes
1 answer

Zend Global Variable in an Extension Persisting Across Multiple Requests

As the title explains, I want to maintain an information across requests from multiple clients. Let me put in a simple example to explain what I want. This example is just for illustration of my question and not the purpose of the post. Example: I…
Karthick
  • 2,844
  • 4
  • 34
  • 55
4
votes
1 answer

In __destruct(), how can you see if an exception is currently in flight?

How can I see if an exception is currently in flight, i.e. the stack is unwinding? In the example below how would you implement isExceptionInFlight()?
Erik van Velzen
  • 6,211
  • 3
  • 23
  • 23
4
votes
2 answers

Understanding zend_execute APIs

I have looked around a lot and never got a good book or any online documentation on zend_extensions [found quite some on PHP extensions but not much on zend_extensions]. I am writing an extension and would like to do the following: 1. Capture the…
Prasanth K
  • 71
  • 7
4
votes
1 answer

How can PHP's foreach() be successfully nested on a single array?

Consider the following code: $a = [1, 2, 3]; foreach ($a as $x) { foreach ($a as $y) { echo "$x $y\n"; } } As one would expect, it gives the following result: 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Although happy with the result, I'm…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
4
votes
1 answer

Is the Zend engine embeddable outside of PHP?

One of the original designs of the Zend engine, if I recall, was that it was to be relatively easy to embed for other languages one might wish to create. Basically, the PHP syntax without all the PHP modules. Is this still the case?
Darrell Brogdon
  • 6,843
  • 9
  • 47
  • 62