phpStorm/Xdebug can't show show child arrays of objects - xdebug

I'm trying to debug this code:
public function removeBlankLines() {
$this->qp->find('br');
} // <-- break point is here
When I drill down into the $this object (using phpStorm) I can't see the child array I'm interested in. It just displays "can not get property" Screenshot:
I'm "listen for debug connections" feature. I'm running the script from the command line. PHP version:
[bwood#mbp ~]$ php -v
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
Maybe related: http://bugs.xdebug.org/view.php?id=996?

http://bugs.xdebug.org/view.php?id=686
It's all about how such classes (SplObjectStorage, ArrayObject and alike) are implemented internally:
this is because objects of the class SplObjectStorage are not user land PHP objects but special super duper internal ones. A similar situation will happen with many other internal PHP classes.
AFAIK nothing can be done on PhpStorm's side until xdebug will be able to "support" them.
UPDATE: The aforementioned xdebug ticket was resolved for xdebug 2.3.3 quite some time ago (latest stable xdebug version is 2.4.1) and it should be possible to view such classes in debugger.

Upgrade your xdebug to version 2.3.3, it has fixed the problem
http://bugs.xdebug.org/view.php?id=686#c3116
If you are running vagrant make sure that you upgrade xdebug in
vagrant virtual machine.
Upgrade instructions can be obtained form http://xdebug.org/wizard.php
If upgrading is not an option, you can dump the contents as a last
resort.
In evaluate expression you can try something like
file_put_contents('dump.txt', var_export($requiredVariable,true));

You will also get a ! can not get property error if the property you are attempting to inspect is inherited from a parent class and not visible from your current scope.
Example:
xDebug will annotate the relevant property like such:
$childClass = {path\to\child\Child}
*path\to\class\Parent*property = {path\to\property\Property}
Where:
Parent is the base class
Child is the extending class
property is the inherited property, defined on Parent
Note the asterisk * which identify this case and denote 'not visible from current scope'.
Solution:
The quick solution to enable debugging is to set the parent's property's visibility to public.
ie
class Parent {
public $property; // instead of private or protected
}
class Child extends Parent{
// You can now inspect parent::$property for instances of Child
}
Remember to set the property visibility back to the correct value when finished testing.

Linux LDME2
php5.6.30-0+deb8u1
xdebug v2.5.3
I tryed this recept.
php -i | xclip -selection clipboard
Put to, and followed the instructions
https://xdebug.org/wizard.php
I got this result (can not get property)
sha256sum ~/xdebug-from-src/xdebug-2.5.3/modules/xdebug.so
afbb70941387ff1e191433d2a09ff42a393caac773194c0e9004b844a0f3d73b
I finded fix for this problem. Instead build from source, need install from pecl
sudo pecl install xdebug
sha256sum /usr/lib/php5/20131226/xdebug.so
b82f2a4ab101323d3600a79223143e2eefe941d404c88af2bd7434fd47caaf13
php -v
PHP 5.6.30-0+deb8u1 (cli) (built: Feb 8 2017 08:50:21) Copyright (c)
1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016
Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans

Related

Configure xdebug on portable drive

I am trying to set xdebug. I do use XAMPP portable, PHP v 7.4.11. I downloaded dlls php_xdebug-3.0.2-7.4-vc15-x86_64.dll and php_xdebug-3.0.2-7.4-vc15-nts-x86_64.dll and put them in \xampp\php\ext. Then I set php.ini file:
implicit_flush = On
zend_extension_ts = H:\xampp\php\ext\php_xdebug-3.0.2-7.4-vc15-x86_64.dll
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.profiler_enable = 0
xdebug.profiler_output_dir = \tmp
xdebug.dump_globals=On
xdebug.show_exception_trace=On
xdebug.collect_params=4
I restarted server, but I can not see any info about xdebug at http://localhost/dashboard/phpinfo.php or among modules in php shell. I have tried both downloaded dlls, various ports, relative/absolute path. Nothing works. There are a few tutorials online, but they might be out of date, or is there problem with portable setting? Any idea, please?
I changed dll`s path and settings:
zend_extension=php_xdebug-3.0.2-7.4-vc15-x86_64.dll
[XDebug]
xdebug.mode=debug
xdebug.client_host = localhost
xdebug.client_port = 9003
xdebug.remote_handler="dbgp"
xdebug.output_dir = H:\xampp\tmp
Now after php -v in php console I get:
PHP 7.4.11 (cli) (built: Sep 29 2020 13:18:06) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
So that is good. At http://localhost/dashboard/phpinfo.php:
According to https://wiki.php.net/internals/extensions, since php 5.5 there is no needed to fill whole path to dll, only it`s name

PHPUnit gives No Code Coverage Driver Is Available

I have a laravel project and I tried to run phpunit to give me a coverage report. I ran the command vendor/bin/phpunit --coverage-html storage/test-output-data/coverage-html and it gave the output:
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
Error: No code coverage driver is available
I tried to resolve this situation by doing a sudo pecl install pcov, but running the phpunit still gave the same error above.
I noticed that I have the file /usr/lib/php/20170718/pcov.so. So I added the line extension=/usr/lib/php/20170718/pcov.so to my /etc/php/7.4/cli/php.ini file. But when I type php -v, I get this error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20170718/pcov.so' (tried: /usr/lib/php/20170718/pcov.so (/usr/lib/php/20170718/pcov.so: undefined symbol: _zval_ptr_dtor), /usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so (/usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.4.11 (cli) (built: Oct 10 2020 19:44:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
I also have a folder called /usr/lib/php/20190902 but it does not have a pcov.so file.
I also tried doing a sudo pecl install xdebug, but I run into similar errors as above where phpunit says there's no driver and typing php -v says some global variable is missing similar to the pcov issue.
What am I doing wrong?
I noticed that I have the file /usr/lib/php/20170718/pcov.so. So I added the line extension=/usr/lib/php/20170718/pcov.so to my /etc/php/7.4/cli/php.ini file.
This file is for PHP 7.2 (based on 20170718 part) while you are trying to use it in PHP 7.4.
You need to get the right version of Xdebug (or PCOV) for your PHP 7.4. (NOTE: for PHP 7.4 the API version (and the right folder in the path) will be 20190902.)
Try this solution from the following answer to switch / install extensions via PECL for specific PHP version (7.4 instead of your current 7.2): https://stackoverflow.com/a/54594604/783119
sudo pecl -d php_suffix=7.4 install <package-name>
This has nothing to do with PHPUnit. You have a problem with your PHP environment: "PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20170718/pcov.so' (tried: /usr/lib/php/20170718/pcov.so (/usr/lib/php/20170718/pcov.so: undefined symbol: _zval_ptr_dtor), /usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so (/usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0"
You just need to install xdebug, so the coverage knows how to run.
For example, for PHP 7.1, it's this package:
sudo apt install php7.1-xdebug
Just fixed it today for my scenario. In your case, just change the PHP version to:
sudo apt install php7.4-xdebug

Xdebug doesn't show up as a module

System:
OS Name Microsoft Windows 10 Pro
Version 10.0.19041 Build 19041
dll location and version:
C:\xampp\php\ext\php_xdebug-2.9.8-7.4-vc15-x86_64.dll
php.ini info:
C:\xampp\php\php.ini
[XDebug]
zend_extension = C:\xampp\php\ext\php_xdebug-2.9.8-7.4-vc15-x86_64.dll
phpinfo():
This program makes use of the Zend Scripting Language Engine: Zend
Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.9.8, Copyright (c) 2002-2020, by Derick Rethans
php -v output:
PHP 7.4.3 (cli) (built: Feb 18 2020 17:29:57) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
When I run php -m, the output is
[PHP Modules]
(a bunch of modules, but no xdebug)
[Zend Modules]
(empty)
Where do I go from here?
I would bet your php_xdebug-2.9.8-7.4-vc15-x86_64.dll is just not compatible with your PHP.
Double check if you don't see anywhere something like
Failed loading C:\xampp\php\ext\php_xdebug-2.9.8-7.4-vc15-x86_64.dll
Also check if your edited php.ini is really used by your php binary.
In my Windows box I have zend_extension=php_xdebug-2.9.8-7.4-vc15-x86_64.dll in php.ini and PHP 7.4.10 (cli) ( ZTS Visual C++ 2017 x64 ) and it works like charm.
Check NTS vs ZTS. Maybe you should use php_xdebug-2.9.8-7.4-vc15-nts-x86_64.dll

Configure PHP Server in PHPStorm with Vagrant on Windows 7

On my local dev machine, I have a Vagrant box with this IP 172.22.22.22. On the box I have installed PHP and Xdebug.
php --version
PHP 5.4.24-1~dotdeb.0 (cli) (built: Jan 12 2014 19:26:20)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
I used the following config for Xdebug:
zend_extension="/usr/lib/php5/20100525+lfs/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_connect_back = 1
But when I configure File --> Settings --> PHP --> Server and put in the values for everything.
I check "Use path mappings ..." and add an "Absolute path on the server" for my project "File/Directory".
When I click "Validate remote environment" I choose the deployment server and leave local path for the validation script for the local path to the project. Then I click "Validate". However, I get the error message "Please, configure path mapping for the validation directory".
But I thought that was what I did in the step above, when I checked the "Use path mappings". But do I misunderstand what the validation directory and validation script is?
I just ran in to the same issue.
Project Settings -> PHP -> Servers. Add your server here. I called mine Test. In my hosts file I've called it test.vagrant, so the host is also called that (not sure if that's right).
Next, I had to add on path mappings, which is the error we were both having. This is not the best way, but it worked.
Click validate remote environment
Add your local server. I created a new server, of type "In Place"
Set up your mappings. In my test project, I have two folders, vagrant and www. Under www I have test. So I mapped the local folder test to an absolute web path of / .
Click ok, and get back to the PHP Servers screen.
Click the checkbox, Use path mappings
Map the local folder to the remote absolute path, in my case it is /var/www/test
And that should remove the error message.
Actually getting xdebug to work is something I haven't managed to do yet. So this information may not help with that, but it will definitely remove the error message.
Just create one more directory "validation" on your local computer and create additional mapping in Deployment->Mappings. Example of my Deployment->Mappings settings:
Local Path | Deployment path | Web path
------------------|-----------------------|-------------
c:\src\validation | /var/www/validation | /validation
After this validation should start.

xdebug not connecting with client?

The xdebug server doesn't connect to any of the clients on port 9000 ie:Netbeans IDE ,debugclient etc.xdebug is shown in phpinfo output.The above clients keep on waiting for the connection to be established.when ever I try to run a php script from the cli it gives the following warning message:
"PHP Warning: Module 'xdebug' already loaded in Unknown on line 0"
The 9000 port has been opened and shows up in the netstat --numeric-port -l command.
I have no idea what might have gone wrong.I have checked all the configuration files,everything seems ok. Any help will be appreciated.
Section of my configuration files
Linux abc.localdomain 3.1.1-2.fc16.x86_64 #1 SMP Mon Nov 14 15:46:10 UTC 2011 x86_64
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans
[Zend]
zend_extension=/usr/lib64/php/modules/xdebug.so
[XDebug]
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.remote_log=/var/log/xdebug.log
php_api no. coincides
Xdebug Simple DBGp client (0.10.0)
Copyright 2002-2007 by Derick Rethans.
- libedit support: enabled
Waiting for debug server to connect.
Is it black magic!!
Thank You
It was actually Selinux not allowing Httpd to connect to other network resources.
Setting the boolean for httpd solved the problem:
setsebool -P httpd_can_network_connect on
OS Fedora 16-X_64
For me the solution was
sudo chcon -R -h -t /path/to/xdebug.so
meaning SELinux now allows httpd to execute this shared object.

Resources