views:

24

answers:

1

Hi Guys,

Php has a Zend Engine.. The zend engine provides fopen.. Php also provides fopen...

But when we call fopen, php's fopen is called.. I have three questions here

  1. What is the purpose of the /php--Nn/ext folder .
  2. Do the functions in ext folder need to be recompiled everytime they are changed?
  3. Do the functions in the ext folder (if they happen to have same name as zend functions) over-ride the zend functions..
+1  A: 

What is the purpose of the /php--Nn/ext folder

It contains the PHP extensions, i.e., the things built on top of the Zend Engine that actually provide PHP functions and the built-in objects.

Do the functions in ext folder need to be recompiled everytime they are changed?

Yes, if you want the change to be reflected in the binaries.

Do the functions in the ext folder (if they happen to have same name as zend functions) over-ride the zend functions..

You're mistaken, the Zend Engine does not define the PHP function fopen. In fact, the Zend Engine provides no PHP functions. It can be compiled independently and used for something completely unrelated to PHP. The Zend Engine actually provides a few PHP functions (declared with ZEND_FUNCTION), see zend_builtin_functions.c. PHP_FUNCTION is actually a synonymous to ZEND_FUNCTION, but relying on ZEND_FUNCTION to declare PHP functions is an abstraction violation.

You may be confusing the PHP function function (declared internally as PHP_FUNCTION(fopen)) with some other C function called fopen (like the one in the standard C library).


As to whether Zend provides a file open function... What I could find:

  • A true global that's a pointer to a open function in zend.c. This is used by zend_stream_open, whose call hierarchy suggests is used when opening include files.
  • A small wrapper around the standard C library that is used a fall-back value for said global.

I imagine the reason for providing a global with a function pointer is so that it can be substituted for e.g. TSRM or the Phar extension.

Artefacto
It isn't true that ZE doesn't provide userland PHP functions. It's possible declaring such functions using the ZEND_FUNCTION() macro. Zend/zend_builtin_functions.c contain a few of those, like get_declared_classes(), func_num_args(), etc.
Daniel Egeberg
@Daniel You're right, I'll edit the answer.
Artefacto
guys.. I din mean that zend provides php functions.. but doesnt zend provide a file open function??
Karthick
@Kar See my edit. If it doesn't satisfy you, tell what you're talking about -- where is that file open fucntion you're talking about (name, file, line).
Artefacto