Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xdebug breaks on access to class static property

Tags:

php

docker

xdebug

I've a problem with Xdebug in my development 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 debugging the code:

<?php
class A {
    static private $a;

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

A::init();

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

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

If I don't step into that line, the debugging session continues without any problems.

What's wrong?

like image 271
Jakub Filipczyk Avatar asked Sep 14 '15 18:09

Jakub Filipczyk


People also ask

How does xdebug remote work?

When Xdebug is running, it will call back to your IDE (like PhpStorm or VS Code) from the server where it's running. Your IDE will sit and listen for that connection on a specific port (typically port 9000 or 9003).


2 Answers

I think it's a bug somewhere in XDebug - see these bug reports

  • http://bugs.xdebug.org/view.php?id=1185
  • https://github.com/docker-library/php/issues/133

Meanwhile you may be able to sort of work around the issue by using the xdebug_break() function just AFTER the line that's throwing the exception and continue debugging from there. I tried setting a breakpoint on the line after the exception is thrown and I found that a breakpoint wasn't enough to stop it throwing an exception.

Not a perfect solution but hopefully those bugs will get fixed soon.

Update: The problem has been nailed down to a combination of a specific version of PHP with a specific version of Xdebug and a specific compiler used for some images. A potential solution has been proposed in the docker-library bug report, which involves installing specific versions of these packages, if you're using Docker.

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
like image 93
ec2011 Avatar answered Oct 07 '22 19:10

ec2011


The error described can only be reproduced in the official PHP5 images. PHP 7 images work just fine, and when building a custom PHP5 FPM image from jessie or ubuntu, the error also does not occur.

like image 42
willydee Avatar answered Oct 07 '22 20:10

willydee