php: Xdebug breaks on access to class static property

I’ve a problem with xdebug in my dev environment

FROM library/php:5.5-apache

RUN apt-get -qqy update && apt-get -qqy install \ 
               libpq-dev \
               libmcrypt-dev \
               libxml2-dev \
               ssl-cert \
               vim \
               git \
               mc \
        && rm -r /var/lib/apt/lists/*

# compile and add xdebug
RUN pecl install xdebug \
    && echo "zend_extension=xdebug.so" >> "/usr/local/etc/php/conf.d/xdebug.ini"

# configure apache and vhosts
RUN a2enmod rewrite ssl \
        && a2ensite 000-default default-ssl

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
ENV APACHE_LOCK_DIR /var/lock/apache2

CMD ["apache2-foreground"]

Xdebug settings:

[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.remote_host=172.17.42.1
xdebug.remote_port=9000

Everything works good but one thing. When debbuging code:

<?php
class A {
    static private $a;

    static public function init() {
        self::$a = 123;
    }
}

A::init();

If i set breakpoint on self::$a = 123; or step into the line then i get:

Fatal error: Access to undeclared static property: A::$a

If i don’t step into that line debugging session continous without any problem.

I tried different xdebug versions, different debug clients (PhpStorm and Netbeans), different ways to install xdebug (pecl, compile from source). Nothing worked. I believe there is some problem in the the official image.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 8
  • Comments: 39 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Still had this problem on PHP 5.6.40.

Constructed the following for my Dockerfile (basing off of official PHP image):

FROM php:5.6-fpm-stretch

(...)

# Compile and install xdebug with the static property fix
RUN BEFORE_PWD=$(pwd) \
    && mkdir -p /opt/xdebug \
    && cd /opt/xdebug \
    && curl -k -L https://github.com/xdebug/xdebug/archive/XDEBUG_2_5_5.tar.gz | tar zx \
    && cd xdebug-XDEBUG_2_5_5 \
    && phpize \
    && ./configure --enable-xdebug \
    && make clean \
    && sed -i 's/-O2/-O0/g' Makefile \
    && make \
    # && make test \
    && make install \
    && cd "${BEFORE_PWD}" \
    && rm -r /opt/xdebug

(...)

Now works. Hope this solution helps someone that wishes to keep using the official PHP images. Saw a comment that it only affects Debian ‘jessie’, but had no luck with ‘stretch’ either 😦

The solution from Wilkolicious worked for me on PHP 5.4.45 and Xdebug 2.4.1 on Debian Jessie, docker image php:5.4-fpm. I just replaced 2_5_5 with 2_4_1 in both places in his instructions.

I still needed to do RUN docker-php-ext-enable xdebug after the RUN line he gave.

BEFORE

RUN pecl install xdebug-2.4.1
RUN docker-php-ext-enable xdebug

AFTER

RUN BEFORE_PWD=$(pwd) \
    && mkdir -p /opt/xdebug \
    && cd /opt/xdebug \
    && curl -k -L https://github.com/xdebug/xdebug/archive/XDEBUG_2_4_1.tar.gz | tar zx \
    && cd xdebug-XDEBUG_2_4_1 \
    && phpize \
    && ./configure --enable-xdebug \
    && make clean \
    && sed -i 's/-O2/-O0/g' Makefile \
    && make \
    # && make test \
    && make install \
    && cd "${BEFORE_PWD}" \
    && rm -r /opt/xdebug
RUN docker-php-ext-enable xdebug

If it’s helpful to anyone, I’ve made https://github.com/chrissound/dockercompose_phpapachemysql_ubuntu

You’re able to install Xdebug following vanilla Ubuntu instructions.

The below worked for me:

FROM php:5.6.3-apache

# XDebug
RUN yes | pecl install xdebug \
    && yes | apt-get update \
    && yes | apt-get install php5-xdebug \
    && echo "zend_extension=/usr/lib/php5/20131226/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini \
		&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
	  && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini

Previous to this I had: docker-php-ext-enable xdebug somewhere in the above.

The fix has been committed.

[2016-12-01 15:31 UTC] dmitry@php.net The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/.

For Windows:

http://windows.php.net/snapshots/

Thank you for the report, and for helping us make PHP better.

@nei did you try my solution a bit further up?

bingo. Same here .

PHP 5.6.30 (cli) (built: Jul  4 2017 04:28:04)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

Looks like this fix pushed to master & php-5.6 branches. I hope it will be included to 5.6.29. https://github.com/php/php-src/commit/1cd566e13f915ccd06a1140d04d4d946748ad021