php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74293 Order of extensions loaded in php.ini affects function calls
Submitted: 2017-03-22 19:38 UTC Modified: 2017-08-20 04:22 UTC
From: yukiwongky at gmail dot com Assigned:
Status: No Feedback Package: Dynamic loading
PHP Version: 7.1.3 OS: Darwin
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: yukiwongky at gmail dot com
New email:
PHP Version: OS:

 

 [2017-03-22 19:38 UTC] yukiwongky at gmail dot com
Description:
------------
This only happens in Mac (I've tested it on Sierra and Al Capital, but I'm not sure if older Mac OS versions have this problem. But Windows and Linux (Ubuntu and CentOS) don't seem to have this problem.

I have two extensions and they have a few common function names. When I use these extensions in Windows or Linux, the order in which I put them in php.ini doesn't matter. However, when I use the extensions on Mac, the function that is in the first loaded extension is always called. For example, I have extension A and B. When I'm using API's from B, I would expect the function in B to be called. However, if I loaded A before B in php.ini, the function of the same name in A is called.

For now I have managed to have a workaround for it by changing the function names / putting them into their own namespace. However, I am concerned that what if some other extension that's not created by me also have the same function names as the ones in my extensions and some user load that extension before mine.

Expected result:
----------------
I expect to see the order of which I load the extensions do not affect which function of the common name is called.

Actual result:
--------------
The function of the extension that is loaded first is executed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-22 19:42 UTC] nikic@php.net
When you say "function", are you referring to PHP functions registered by your extension, or to C functions that your extension defines?
 [2017-03-22 19:48 UTC] yukiw at simba dot com
he C functions that my extension defines
 [2017-03-22 19:53 UTC] nikic@php.net
What linkage and visibility does your C function use? (If you don't know, can you paste the complete function signature, including any attributes before it?)
 [2017-03-22 20:10 UTC] yukiwongky at gmail dot com
-: yukiw at simba dot com +: yukiwongky at gmail dot com
 [2017-03-22 20:10 UTC] yukiwongky at gmail dot com
The examples I found in the sqlsrv and pdo_sqlsrv extensions are:

sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code);

struct stmt_option_ss_scrollable : public stmt_option_functor {
    virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC );
};
 [2017-04-02 01:50 UTC] ab@php.net
Seems Nikita's guess is exactly what happens. There maybe several scenarios, but all are related to the actual linker and loader process. For example the loader might only use the first refered symbol it finds, if the DSOs export duplicated symbols. Another situation, if some DSO was linked the way, that some library overrides symbols in the object files. The symbol in the signature you show should not be exported, however it could happen if compiler does it by default. It is quite possible, that the system loader will only use the symbol encountered first.

The extensions are not the core PHP extensions, so it doesn't look like a core bug. I'd suggest first to consult your compiler documentation and ensure the symbols not explicitly exported are kept private in the binaries.

Thanks.
 [2017-08-12 01:05 UTC] ajf@php.net
-Status: Open +Status: Feedback
 [2017-08-20 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 19 08:03:37 2021 UTC