7.1 adds a backslash to class names and cannot be instantiated

Issue #52 resolved
Former user created an issue

the default is empty and it doesn't work on php 7.1 when installing with pecl:

bash# pecl install event

Then I can see declared classes with the backslash proceeding...

bash-4.2# php -r "var_dump(get_declared_classes());" | grep Event
  string(6) "\Event"
  string(10) "\EventBase"
  string(12) "\EventConfig"
  string(17) "\EventBufferEvent"
  string(12) "\EventBuffer"
  string(13) "\EventDnsBase"
  string(14) "\EventListener"
  string(20) "\EventHttpConnection"
  string(10) "\EventHttp"
  string(17) "\EventHttpRequest"
  string(10) "\EventUtil"
  string(16) "\EventSslContext"
  string(15) "\EventException"

but when I try to use it with or without a backslash it doesn't work..

bash-4.2# php -r "new Event();"
PHP Fatal error:  Uncaught Error: Class 'Event' not found in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1
bash-4.2# php -r "new \Event();"
PHP Fatal error:  Uncaught Error: Class 'Event' not found in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1

When I build manually:

# phpize && ./configure --with-event-ns=no
# make && make install

then I see there is no backslash:

bash-4.2# php -r "var_dump(get_declared_classes());" | grep Event
  string(5) "Event"
  string(9) "EventBase"
  string(11) "EventConfig"
  string(16) "EventBufferEvent"
  string(11) "EventBuffer"
  string(12) "EventDnsBase"
  string(13) "EventListener"
  string(19) "EventHttpConnection"
  string(9) "EventHttp"
  string(16) "EventHttpRequest"
  string(9) "EventUtil"
  string(15) "EventSslContext"
  string(14) "EventException"

and I can try to instantiate an object:

bash-4.2# php -r "new Event();"
PHP Warning:  Event::__construct() expects at least 4 parameters, 0 given in Command line code on line 1

it does actually work when really used in a project.

I believe this should be changed in the package.xml

  <configureoption default="no" name="with-event-ns" prompt="PHP Namespace for all Event classes" />

Comments (4)

  1. Jordan Raub

    is there a way to change this from anonymous to me? I accidentally didn't sign in before creating it. Thx

  2. Ruslan Osmanov repo owner

    I don't see a way to change the original author, but let's leave it as is. You can subscribe to this ticket as a "watcher".

    Did you accept the defaults when the pecl install event command asked for input?

    Please run the following from the source root directory:

    pecl install package.xml
    

    (on behalf of root) accept defaults, and look if the build fails. If it fails, try the same command, but this time set the namespace to no. If it still doesn't work, please try to apply the following patch:

    diff --git a/config.m4 b/config.m4
    index 88f7893..44049e8 100644
    --- a/config.m4
    +++ b/config.m4
    @@ -27,7 +27,7 @@ PHP_ARG_WITH(event-openssl, for OpenSSL support in Event,
     [  --with-event-openssl Include libevent OpenSSL support], yes, no)
    
     PHP_ARG_WITH(event-ns, for custom PHP namespace in Event,
    -[  --with-event-ns[=NS] Set custom PHP namespace for all Event classes], [], no)
    +[  --with-event-ns[=NS] Set custom PHP namespace for all Event classes], no, no)
    
     PHP_ARG_WITH(openssl-dir, for OpenSSL installation prefix,
     [  --with-openssl-dir[=DIR]  Event: openssl installation prefix], no, no)
    diff --git a/package.xml b/package.xml
    index 3417bfb..ad9eb94 100644
    --- a/package.xml
    +++ b/package.xml
    @@ -198,7 +198,7 @@
         <configureoption default="no" name="with-event-pthreads" prompt="Include libevent's pthreads library and enable thread safety support in Event"/>
         <configureoption default="yes" name="with-event-extra" prompt="Include libevent protocol-specific functionality support including HTTP, DNS, and RPC"/>
         <configureoption default="yes" name="with-event-openssl" prompt="Include libevent OpenSSL support"/>
    -    <configureoption default="" name="with-event-ns" prompt="PHP Namespace for all Event classes"/>
    +    <configureoption default="no" name="with-event-ns" prompt="PHP Namespace for all Event classes"/>
         <configureoption default="no" name="with-openssl-dir" prompt="openssl installation prefix"/>
       </extsrcrelease>
       <!--{{{ changelog-->
    
  3. Jordan Raub

    I'm running in a docker build so I'm doing this:

    RUN pecl install event
    

    which runs the defaults

    now the run is like this:

    RUN pecl-event-install.sh
    

    and pecl-event-install.sh is this:

    #!/bin/bash
    
    set -e
    
    XML_FILE=package.xml
    
    cd /opt/
    
    mkdir pecl-event
    
    cd pecl-event
    
    pecl download event
    
    tar zxf event-*
    
    EVENT_VERSION=$(xmllint --xpath "/*[local-name()='package']/*[local-name()='version']/*[local-name()='release']/text()" package.xml)
    
    cd event-$EVENT_VERSION
    
    phpize && ./configure --with-event-ns=no
    
    make && make install
    

    so if you update to a new version when building it will work fine with the $EVENT_VERSION grabbing the proper version from the xpath.

  4. Log in to comment