Class name conflict with Laravel and Lumen

Issue #46 resolved
Don Schoeman
created an issue

The extension exports a class with the name "Event", however, two very popular frameworks called Laravel (and its derivative Lumen) have class names that conflicts with the name of the Event class. So one cannot enable the extension while running into trouble using these frameworks.

The only possible solution seems to either rename the Event class or to introduce a namespace into the extension. Perhaps one can start by adding a compiler flag?

Comments (17)

  1. Ruslan Osmanov repo owner

    Unfortunately, I'm not very familiar with Laravel so I can't give you a foolproof solution now. Have you tried extending Event as shown in this answer on StackOverflow?

    I noticed that there is a similar issue with Redis class conflicting with different PECL extensions. The official Laravel documentation suggests to rename the built-in class using config/app.php:

    Note: If you have the Redis PHP extension installed via PECL, you will need to rename the alias for Redis in your config/app.php file.

  2. Don Schoeman reporter

    Thanks for the feedback. The problem in my case is a little more complex as I am not using Facade's so I can't provide an alias for its Event class. I am not sure why there is a name conflict since Laravel/Lumen's classes all have namespaces. I am still looking for solutions and will definitely provide further feedback here. Note that I do recognise that you can't simply change your Event class name or register your classes under a namespace as that would cause problems downstream for everyone using your extension. On the other hand, the frameworks mentioned already use namespaces so they will not make changes either.

  3. Ruslan Osmanov repo owner
    • changed status to open

    I think it can be done via package options:

    <configureoption default="\" name="with-event-namespace" prompt="Namespace for all Event classes"/>
    

    It should be easy, but I haven't much free time lately so I can't promise to do it soon.

  4. Ruslan Osmanov repo owner

    Can be done as in issue-46 branch. But there is a little problem -- tests. Well, we could construct objects dynamically:

    $eventConfigClass = PHP_EVENT_NS . '\\EventConfig';
    $cfg = new $eventConfigClass()
    

    But somehow I don't like this idea. Maybe someone will suggest a better solution?

  5. Don Schoeman reporter

    Hi, I finally had some time to test the custom namespace option.

    I did the test after checking out branch "issue-46" and using the following ./configure options: ./configure --with-event-core --with-event-extra --with-event-ns='Osmanov'

    I then did make and sudo make install. However, I then discovered the following error when running php cli:

    PHP         : /usr/bin/php7.1 
    Warning: PHP Startup: Unable to load dynamic library '/home/vagrant/pecl-event/modules/event.so' - /home/vagrant/pecl-event/modules/event.so: undefined symbol: zim_EventSslContext_setMinProtoVersion in Unknown on line 0
    

    I then changed back to master branch, ran ./configure and make, sudo make install again and received the same error.

    This is the results of make test:

    /bin/bash /home/vagrant/pecl-event/libtool --mode=install cp ./event.la /home/vagrant/pecl-event/modules
    libtool: install: cp ./.libs/event.so /home/vagrant/pecl-event/modules/event.so
    libtool: install: cp ./.libs/event.lai /home/vagrant/pecl-event/modules/event.la
    libtool: finish: PATH="/home/vagrant/.composer/vendor/bin:/home/vagrant/bin:/home/vagrant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin" ldconfig -n /home/vagrant/pecl-event/modules
    ----------------------------------------------------------------------
    Libraries have been installed in:
       /home/vagrant/pecl-event/modules
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the '-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the 'LD_RUN_PATH' environment variable
         during linking
       - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to '/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
    
    Build complete.
    Don't forget to run 'make test'.
    
    PHP Warning:  PHP Startup: Unable to load dynamic library '/home/vagrant/pecl-event/modules/event.so' - /home/vagrant/pecl-event/modules/event.so: undefined symbol: zim_EventSslContext_setMinProtoVersion in Unknown on line 0
    PHP Warning:  PHP Startup: Unable to load dynamic library '/home/vagrant/pecl-event/modules/event.so' - /home/vagrant/pecl-event/modules/event.so: undefined symbol: zim_EventSslContext_setMinProtoVersion in Unknown on line 0
    
    =====================================================================
    PHP         : /usr/bin/php7.1 
    Warning: PHP Startup: Unable to load dynamic library '/home/vagrant/pecl-event/modules/event.so' - /home/vagrant/pecl-event/modules/event.so: undefined symbol: zim_EventSslContext_setMinProtoVersion in Unknown on line 0
    
    PHP_SAPI    : cli
    PHP_VERSION : 7.1.1-1+deb.sury.org~xenial+1
    ZEND_VERSION: 3.1.0
    PHP_OS      : Linux - Linux homestead 4.4.0-51-generic #72-Ubuntu SMP Thu Nov 24 18:29:54 UTC 2016 x86_64
    INI actual  : /home/vagrant/pecl-event/tmp-php.ini
    More .INIs  :   
    CWD         : /home/vagrant/pecl-event
    Extra dirs  : 
    VALGRIND    : Not used
    =====================================================================
    TIME START 2018-04-10 09:50:02
    =====================================================================
    SKIP Check for event presence [tests/01-load.phpt] 
    FAIL Check for event configuration features [tests/02-features.phpt] 
    FAIL Check for event_add and event_del [tests/03-event-del.phpt] 
    SKIP Check for event_buffer sockets [tests/04-bevent-socket.phpt] reason: - event extension not available.
    FAIL Check for manipulation with buffer position [tests/05-buffer-pos.phpt] 
    FAIL Check for timer event basic behaviour [tests/06-timer.phpt] 
    SKIP Check for EventListener error behaviour [tests/07-listener-error-win32.phpt] reason: Event extra functions are disabled
    SKIP Check for EventListener error behaviour [tests/07-listener-error.phpt] reason: Event extra functions are disabled
    FAIL Check for EventBuffer methods' behaviour [tests/08-buffer.phpt] 
    FAIL Check for gc_collect_cycles appled after event free [tests/09-gc-cycles.phpt] 
    FAIL Check for event destructor depending on the data property value [tests/10-event-data-dtor.phpt] 
    FAIL Check for get_gc property handler [tests/11-gc-cycles.phpt] 
    SKIP Check for SEGFAULT with serialization functions [tests/12-serialization.phpt] reason: Event extra functions are disabled
    FAIL Check for EventBufferEvent::createPair() [tests/13-bevent-pair.phpt] 
    SKIP Check for EventHttpConnection::__construct() error behavior [tests/14-php5-httpconn-error.phpt] reason: Event extra functions are disabled
    SKIP Check for EventDnsBase::__construct() error behavior [tests/15-php5-dnsbase-error.phpt] reason: Event extra functions are disabled
    SKIP Check for EventHttp::__construct() error behavior [tests/16-php5-http-error.phpt] reason: Event extra functions are disabled
    SKIP Check for Event::set() error behavior in PHP 5 [tests/17-event-settimer-error.phpt] reason: target is PHP version < 7
    SKIP Check for Event::timer() error behavior in PHP5 [tests/18-timer-error.phpt] reason: target is PHP version < 7
    SKIP Check for Event::signal() error behavior in PHP5 [tests/19-event-signal-error.phpt] reason: target is PHP version < 7
    SKIP Check for EventBufferEvent::__construct() error behavior in PHP5 [tests/20-bevent-error.phpt] reason: PHP version < 7
    SKIP Check for EventBufferEvent::createSslFilter() behavior [tests/21-bevent-sslfilter.phpt] reason: Event extra functions are disabled
    SKIP Check for EventBufferEvent::sslSocket() error behavior [tests/21-bevent-sslsocket.phpt] reason: Event extra functions are disabled
    SKIP Check for EventBufferEvent::createPair() error behavior in PHP5 [tests/22-php5-bevent-pair-error.phpt] reason: target is PHP version < 7
    SKIP Check for EventListener error behaviour in PHP5 [tests/23-php5-listener-error.phpt] reason: target is PHP version < 7
    SKIP Check for EventBufferEvent::createSslFilter() error behavior [tests/24-php5-bevent-sslfilter-error.phpt] reason: Event extra functions are disabled
    SKIP Check for EventBufferEvent::sslSocket() error behavior [tests/25-php5-bevent-sslsocket-error.phpt] reason: Event extra functions are disabled
    SKIP Check for EventHttp* objects debug info [tests/26-http-debug-info.phpt] reason: Event extra functions are disabled
    SKIP Check for EventUtil::createSocket [tests/27-event-util-create-socket.phpt] reason: sockets extension is not available
    SKIP Check for EventBufferEvent SSL features [tests/28-bevent-ssl.phpt] reason: Event is built without EventBufferEvent support
    SKIP Check for EventBufferEvent SSL features, OpenSSL version 1.1.0 and above [tests/28-bevent-ssl1.1.0.phpt] reason: Event is built without EventBufferEvent support
    FAIL Check for EventBuffer::pullup method behavior [tests/29-buffer-pullup.phpt] 
    SKIP Check for EventListener::free behavior [tests/30-listener-free.phpt] reason: Event extra functions are disabled
    FAIL Check for issue #31 [tests/31-issue.phpt] 
    =====================================================================
    TIME END 2018-04-10 09:50:02
    
    =====================================================================
    TEST RESULT SUMMARY
    ---------------------------------------------------------------------
    Exts skipped    :    0
    Exts tested     :   13
    ---------------------------------------------------------------------
    
    Number of tests :   34                11
    Tests skipped   :   23 ( 67.6%) --------
    Tests warned    :    0 (  0.0%) (  0.0%)
    Tests failed    :   11 ( 32.4%) (100.0%)
    Expected fail   :    0 (  0.0%) (  0.0%)
    Tests passed    :    0 (  0.0%) (  0.0%)
    ---------------------------------------------------------------------
    Time taken      :    0 seconds
    =====================================================================
    
    =====================================================================
    FAILED TEST SUMMARY
    ---------------------------------------------------------------------
    Check for event configuration features [tests/02-features.phpt]
    Check for event_add and event_del [tests/03-event-del.phpt]
    Check for manipulation with buffer position [tests/05-buffer-pos.phpt]
    Check for timer event basic behaviour [tests/06-timer.phpt]
    Check for EventBuffer methods' behaviour [tests/08-buffer.phpt]
    Check for gc_collect_cycles appled after event free [tests/09-gc-cycles.phpt]
    Check for event destructor depending on the data property value [tests/10-event-data-dtor.phpt]
    Check for get_gc property handler [tests/11-gc-cycles.phpt]
    Check for EventBufferEvent::createPair() [tests/13-bevent-pair.phpt]
    Check for EventBuffer::pullup method behavior [tests/29-buffer-pullup.phpt]
    Check for issue #31 [tests/31-issue.phpt]
    =====================================================================
    
    You may have found a problem in PHP.
    This report can be automatically sent to the PHP QA team at
    http://qa.php.net/reports and http://news.php.net/php.qa.reports
    This gives us a better understanding of PHP's behavior.
    If you don't want to send the report immediately you can choose
    option "s" to save it.  You can then email it to qa-reports@lists.php.net later.
    Do you want to send this report now? [Yns]: 
    
  6. Ruslan Osmanov repo owner

    @Don Schoeman, looks like a bug. I couldn't reproduce it, but I'll try to find out something, if you send me the full build log including the output of configure.

    As a workaround, try to build with SSL: ./configure --with-event-core --with-event-extra --with-event-openssl.

    By the way, the Bitbucket pipeline has passed.

  7. Don Schoeman reporter

    I have some positive feedback. There were two problems, first I had to use make with the -B flag to unconditionally make all targets, e.g. make -dB, that seemed to solve the above runtime error...

    But then I had a new error: PHP Warning: Cannot load module 'event' because required module 'sockets' is not loaded in Unknown on line 0. The sockets module was definitely loaded though. This in turn was caused by a recent sudo apt upgrade which bumped OpenSSL from OpenSSL 1.0.2g 1 Mar 2016 to OpenSSL 1.1.0h 27 Mar 2018, however, the Vigrant virtualbox was never properly rebooted (I usually just suspend it) and after rebooting it that problem was solved too.

    I can now finally test the namespace configuration again but will have to do so this afternoon. Will let you know how it went.

  8. Don Schoeman reporter

    Thanks, I expected that this may be the case but wasn't sure how I would go about fixing it yet. I just read your post and it will certainly help in the future.

  9. Don Schoeman reporter

    More feedback: I had to rename event.ini to z-event.ini as I kept getting more of the Cannot load module 'event' because required module 'sockets' errors as you mentioned in your post.

    With regards to the namespaces: It seems to be working, I have configured the extensions using './configure --with-event-core --with-event-extra --with-event-ns='Osmanov'' and can now instantiate classes using statements such as new Osmanov\EventBase(). I'm using ReactPHP which in turn uses your extension so I have to create drop-in replacements for their classes but for now it will have to do. Thanks for your work on this, it is much appreciated!

  10. Don Schoeman reporter

    Hi,

    I have tested it with a custom namespace as in my previous comment and it was working fine. Unfortunately I cannot fully test it in a production environment as is but my development tests ran without any trouble. I'm not sure whether that is enough for you to take the risk but I am personally happy with the additional namespace option that you added.

  11. Log in to comment