News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Derick Rethans:
Dead Code
June 18, 2014 @ 10:49:56

In his latest post Derick Rethans talks about something that plagues every project, PHP or otherwise, after its grown to a large enough size: dead code. He's been asked why his Xdebug tool finds this code in places where people don't expect, so he figured he'd answer it once and for all.

The explanation for this is rather simple. Xdebug checks code coverage by adding hooks into certain opcodes. Opcodes are the building blocks of oparrays. PHP converts each element in your script - main body, method, function - to oparrays when it parses them. The PHP engine then executes those oparrays by running some code for each opcode. Opcodes are generated, but they are not optimised. Which means that it does not remove opcodes that can not be executed.

He gets down to the opcode level and shows some output from vld on how things are being executed (and what's not). Using a simple "foo" function example, he shows the execution flow and how the "branches" of executions work through the code. In his case, the "dead code" marker is coming from the line with a closing brace from an "if" statement. He points out that it entirely depends on the lines executed as to what is marked as "dead code".

0 comments voice your opinion now!
dead code xdebug path flow branch vld

Link: http://derickrethans.nl/dead-code.html

blog comments powered by Disqus

Similar Posts

Felix Geisendorfer's Blog: Setting up Xdebug on Mac OS X (or Win32 / Linux)

PHP in Action Blog: Bad code is good for you?

Bob Majdak: Extending an Iterator to use an Iterator to make your code a little cleaner

Project: RIPS - Static Source Code Analyzer for Vulnerabilities in PHP Scripts

Harrie Verveer's Blog: Benchmarking Xdebug


Community Events





Don't see your event here?
Let us know!


community deployment api podcast threedevsandamaybe code framework series tips interview voicesoftheelephpant release laravel introduction conference language list bugfix symfony zendserver

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework