Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xdebug breaks on access to class static property #133

Closed
jfilipczyk opened this issue Sep 15, 2015 · 39 comments
Closed

Xdebug breaks on access to class static property #133

jfilipczyk opened this issue Sep 15, 2015 · 39 comments

Comments

@jfilipczyk
Copy link

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.

@original-brownbear
Copy link

Same here, tested with 5.5.x and 5.6.x with various versions of xdebug.
Same code can be debugged perfectly fine using the same php versions install from the Jessie apt repo.

@gelbehexe
Copy link

Same here, with 5.3, 5.4, 5.5 always newest cgi version self compiled - now using the Zend-Debugger which drives me crazy because it's that slow :-(

@yosifkit
Copy link
Member

yosifkit commented Nov 3, 2015

Any idea on the cause of the problem and how we could fix the images?

@mekanixdk
Copy link

Just a "me too" from here. Been driving me nuts for a couple of days.

@Tschef
Copy link

Tschef commented Nov 14, 2015

Welcome me to the club as well.
+1 for having to deal with weird fatal errors for perfectly fine code.

@parrisvarney
Copy link

Same issue here with the following Dockerfile

FROM php:5.6-apache

COPY ./server/vhost.conf /etc/apache2/sites-enabled/vhost.conf

RUN a2enmod ssl
RUN a2enmod headers
RUN a2enmod rewrite
RUN docker-php-ext-install pdo_mysql mbstring

RUN pecl install -o -f xdebug \
    && rm -rf /tmp/pear \
    && echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=1"       >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_handler=dbgp"   >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_port=9000"      >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini

@booyaa
Copy link

booyaa commented Nov 17, 2015

Presumably xdebug is a remote debugger what os and version is the debug client connecting to on the containers debug server port (9000).

Got some questions:

@jfilipczyk how are your referencing xdebug.ini? host volume mapping? Your xdebug setup differs slightly from @parrisvarney because you're using what looks like the docker0 as a static ip xdebug client.

@parrisvarney your path to xdebug differs from @jfilipczyk is that normal?

Probably unrelated, but has anyone tried UNIX socket option instead of TCP? You can map UNIX sockets using -v.

@parrisvarney
Copy link

@booyaa I've never seen the xdebug path configured as a relative path, but I don't think that's the issue since if it's incorrect the remote debugger wouldn't work at all.

The issue we're seeing is that a seemingly incorrect fatal error arises during run time when a value is assigned to a static class member. This only happens when a breakpoint is set the in the file containing that assignment. Both the php program and xdebug behave normally if the breakpoint is not set.

This issue started last week for me when I switched from a custom Vagrant box build to this premade Docker build, at the same time upgrading from php5.3 to php5.6. The work around is easy enough for me since the error occurs in a config file (don't place a breakpoint), but the scenario is similar enough to what @jfilipczyk is experiencing that I figured I'd add my use case.

@JProof
Copy link

JProof commented Apr 12, 2016

I have the same issue without a docker.
has somebody found an solution or an step-try-to-follow?

@willydee
Copy link

willydee commented May 2, 2016

As noted before, this effect only happens in the official PHP 5 docker builds. When building a PHP 5 container from jessie or a recent ubuntu, xdebug works just fine.
The official PHP 7 builds also don't show the erroneous behavior.

@jahumes
Copy link

jahumes commented Jun 6, 2016

+1. It is happening on the official 5.6 image

@ihorsamusenko
Copy link

+1 =(

@ihor-sviziev
Copy link

ihor-sviziev commented Aug 10, 2016

👍 Any workaround?

@codeorganic
Copy link

There is no known workaround except switch to a different image.

To describe the issue in more detail this only happens after the first breakpoint of a static type. Hitting next breakpoint simple breaks xdebug on this image.

I would love to correct the code with this image but I do not know where to begin as I have never seen an issue as described above.

@ihor-sviziev
Copy link

ihor-sviziev commented Aug 12, 2016

@codeorganic which image i can use as alternative?
Looks like it's xdebug issue https://bugs.xdebug.org/view.php?id=1185. waiting for fix

@hjoelr
Copy link

hjoelr commented Aug 12, 2016

@codeorganic having a suggested alternative would be helpful.

To describe the issue in more detail this only happens after the first breakpoint of a static type. Hitting next breakpoint simple breaks xdebug on this image.

In relation to that statement, I'm pretty sure I tried setting breakpoints that were before the static variable reference and was able to step through the code until it hit the static reference.

@ihor-sviziev When I ran across this bug about 2 weeks ago, I switched to a custom container. I don't guarantee it's bug-free. It's also somewhat customized to our own development environment and subject to change as our development needs change. It may be a helpful jump-off point, though.

@willydee
Copy link

@ihor-sviziev you also may start with a recent debian or ubuntu container and just install your desired PHP version and extensions via Dockerfile. Works pretty well for me.

@ihor-sviziev
Copy link

@willydee could you send your Dockerfile where xdebug works good for you?

@willydee
Copy link

Sure. This is for PHP 5.6; for the latest PHP 7 you may use the official image, which does not show this debugging misbehaviour.

FROM ubuntu:latest

# To use the latest stable PHP version:
RUN apt-get update \
  && apt-get install -y --allow-unauthenticated --no-install-recommends \
  software-properties-common python-software-properties
RUN add-apt-repository ppa:ondrej/php

# Add here whatever extensions you might need
RUN apt-get update \
  && apt-get install -y --allow-unauthenticated --no-install-recommends \
    php5.6-fpm \
    php5.6-xdebug

# Cleanup caches to keep image size small
RUN rm -r /var/lib/apt/lists/*
RUN rm -r /var/cache/apt/*

# For your own php.ini directives
COPY custom.ini /etc/php/5.6/fpm/conf.d/custom.ini

# For your own FPM pool directives
COPY www.conf /etc/php/5.6/fpm/pool.d/www.conf

# Make sure the pidfile directory exists
RUN mkdir /run/php

CMD ["php-fpm5.6", "--nodaemonize", "--fpm-config", "/etc/php/5.6/fpm/php-fpm.conf"]

@ihor-sviziev
Copy link

ihor-sviziev commented Nov 15, 2016

I've contacted with Derick Rethans (Xdebug developer), gived him information about this issue and he was able to reproduce this issue and gave following response:

It's not a bug in Xdebug and it doesn't seem to be that the bug is in PHP either, but rather in the compiler that Jessie uses by default.

So the current conclusion is: compiler bug (or weird interaction between compiler and PHP).

I haven't had the time to file a bug for PHP yet, but I have mailed internals and cc-ed some PHP devs, but they don't seem interested :-(.

You can work around it by changing the -O2 to -O0 in the Makefile file after running "./configure" but before "make". Before you run "./configure", don't forget to run "make clean" first.

I'll try to prepare Dockerfile with that workaround little bit later. I hope it will help us.

Derick also reported bug to PHP: https://bugs.php.net/bug.php?id=73545

@vkvasnytsky
Copy link

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.

@ihor-sviziev
Copy link

ihor-sviziev commented Dec 5, 2016

Looks like this fix pushed to master & php-5.6 branches. I hope it will be included to 5.6.29.
php/php-src@1cd566e

@ihor-sviziev
Copy link

Unfortunately that fix wasn't added to 5.6.29. Waiting for next release...

@ihor-sviziev
Copy link

That commit was included to 5.6.30, but this issue still reproducing =(
@derickr any ideas?

@derickr
Copy link

derickr commented Jan 27, 2017

As I could reproduce this without Xdebug in the mix, I don't think there is much I can do about it.

@chrissound
Copy link

This is a deal breaker for 5.6.3... Could we mention this issue in the readme?

@derickr
Copy link

derickr commented May 30, 2017

@ihor-sviziev Are you sure it was the same problem again?

@chrissound
Copy link

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.

@chrissound
Copy link

@derickr If that question was actually meant for me, yes same issue (Fatal error upon access of static class property).

@tomaszmadeyski
Copy link

Just another "same here" from my side. PHP 5.6.30

@chrissound
Copy link

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.

JeroenBoersma pushed a commit to JeroenBoersma/docker-php that referenced this issue Oct 4, 2017
@nei
Copy link

nei commented Nov 1, 2017

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

@chrissound
Copy link

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

@tianon
Copy link
Member

tianon commented Dec 22, 2017

I'm closing given the solution posted above in #133 (comment) -- this doesn't seem to be an issue specific to our images, but rather the combination of Jessie's compiler + PHP + Xdebug. Since then, PHP has been updated with a fix, and some images are on Stretch (#504).

For further discussion of this topic, I'd recommend posting to the Docker Community Forums, the Docker Community Slack, or Stack Overflow in order to capture a wider user base. Thanks!

@tianon tianon closed this as completed Dec 22, 2017
@mixalistzikas
Copy link

I'm looking for a workaround for php 5.4
"apt-get install php5-xdebug" it only works for >=5.6

@Wilkolicious
Copy link

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 :(

@n3amil
Copy link

n3amil commented May 31, 2019

Same problem with php:5.4.45-apache and pecl install xdebug-2.4.1 & docker-php-ext-enable xdebug. Guess i have to build the image myself...

Persata added a commit to Persata/docker-php-1 that referenced this issue Jun 10, 2019
Uses workaround detailed in github.com/docker-library/php/issues/133 to
compile Xdebug from source with different args. Allows debugging of code
involving static properties without errors.
@boussou
Copy link

boussou commented Apr 22, 2020

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 :(

Note to all 👍 this from @Wilkolicious is the solution. it works on PHP 5.6 on Debian 8 (and even for PHP 5.3 on Debian 8)

inblank added a commit to inblank/docker-php5.6-apache that referenced this issue Sep 15, 2020
@tylercollier
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests