The Acumen software design blog provides you with helpful articles about PHP Development.

This web site provides a good overview.

PHP Development Wikipedia

acumen consulting php development

The Pros and Cons PHP 7.0 Migration

With the planned date for PHP 7’s release rapidly approaching, the PHP internals group is hard at work trying to fix our beloved language as much as possible by both removing artifacts and adding some long desired features. There are many features we could discuss, but in this post, I’d like to focus on three that grabbed my attention.

Recently 5.7 has been moving down the ladder in favor of web developemnt directly to 7. What this means there will be no new version between 5.6 and 7 – even if the new version was only to serve as a warning light to those still stuck on outdated code. Originally, 5.7 was not supposed to have new features, but was supposed to throw out notices and warnings of deprecation about code that’s about to change in v7.

It would also warn about some keywords that are to be reserved in PHP 7, so that people can bring their code up to speed with a sort of “automatic” compatibility checker in the form of an entire PHP version. The thing is, however, as I argue in the newsletter, that most people technologically competent enough to follow PHP in its upgrade path by keeping up with the most recent version aren’t generally the type of people to actually be using code that might break in PHP 7.

Return Types

With a vast majority voting “yes”, PHP is finally getting return types.  Starting with PHP 7, we’ll finally be able to indicate proper return types on functions in the form of:

function foo(): array {
    return [];
}

An improvement? Definitely! But perfect? Sadly, no:

  • the return types can only be what we have for types right now, meaning no scalar values, no return types like string, int, bool, etc. This means that your methods and functions that return such values will still be unsigned. You can remedy this by returning instances of wrappers for such values, but that’s overkill in the vast majority of cases.
  • no multiple return types. If your function returns either an array, or an Iterator object, there’s no way to indicate that via, for example, array|Iterator as we do in docblocks.

Some people also complained about the type declaration being after the closing parenthesis of the argument list, rather than before the function name, but to me, this is nitpicking. Popular languages such as modern C++ use the “after” syntax, and like the RFC states, this preserves the possibility of searching for “function foo” without any necessary regex modifications. What’s more, this is in line with what HHVM uses, so it’s an added unintended compatibility bonus.

Some complaints are about the “strictification” of PHP, but you really find the value of this when you start coding against interfaces or inheriting other people’s code. Besides, as long as it’s optional and its existence does not in any way affect PHP’s general performance or stability, there’s no harm in it. Complaining about it is, to me, akin to complaining about OOP being added to PHP when procedural spaghetti worked so well for most cases back then. Languages evolve, and this is a step in the right direction.


Removing Artifacts

The upcoming version proposes to remove PHP4 style constructors.  Communities anger on this makes me wonder – if you’ve kept such a codebase alive for so long, is there really a need to upgrade to PHP 7? And if there is a need to upgrade to PHP 7, is it not easier to simply hunt down the offending classes and fix their constructors? Surely this is something you can delegate to juniors, given enough unit tests in your code base to make sure it all goes well? And if you don’t have unit tests, if your app is a mess, do you really hope to benefit in any way from moving to PHP 7? Wouldn’t you be better off Modernizing your Application first?

The sentence “This means that code which I wrote 10 years ago should still run today, and should still run 10 years from now.” is, to me, madness – you definitely and absolutely should not expect this of ANY language across major versions.

Granted, some coders are right in that it would take effort to remove the feature, while it would take none to leave it in. But in the long run, it will take more collective effort to fix the problems these constructors sometimes cause, than to remove it now.

My advice to those fearing PHP 7 is – stop. If you don’t want to upgrade, don’t. If you could be on 5.3 or 5.2 for so long (looking at you, CodeIgniter), you can be on 5.6 for another decade – but let us have modern PHP. Leave progress up to those who are willing to accept it.


Scalar type declarations

Scalar type declarations come in two flavours: coercive (default) and strict. The following types for parameters can now be enforced (either coercively or strictly): strings (string), integers (int), floating-point numbers (float), and booleans (bool). They augment the other types introduced in PHP 5: class names, interfaces, array and callable.

<?php
// Coercive mode
function sumOfInts(int ...$ints)
{
return array_sum($ints);
}var_dump(sumOfInts(2, '3', 4.1));

PHP 7

The quick list of changes:

  • PHPNG (next generation of Zend Engine)
  • Scalar type declarations
  • Return type declarations
  • Spaceship operator
  • Anonymous classes
  • Generator return expressions
  • Generator delegation
  • Performance
  • Error handling (Exceptions)
  • Extension API changes

Conclusion

As usual, there’s no shortage of drama in PHP land. Like all major revolutions throughout history, the 7 revolution will also be spilling some blood before producing something awesome. PHP 7 is still a long way off, so even if you’re caught in the crossfire of musket shots, there’s ample time to get to cover. Unless you’ve been sleeping under tank tracks, then there’s little either side can do to help you.

What do you think of these RFCs? How do you feel about PHP 7 in general? Is it heading in the direction you’d like it to head in? Let us know – we want to hear your thoughts!

PHP is a powerful and one of the most popular coding language among web programmers. Majority of the most popular websites on the web are based on PHP programming language. In this article, we are looking to help you choose the best PHP framework for 2014.

Every developer knows that a proper framework enables to create applications quicker, safer and more efficiently. Choosing a right framework before building your application is crucial for robustness and success. PHP frameworks are super useful tools for web development, as they are real time-savers when it comes to creation and maintenance of the PHP website.

Generally framework consists of:

  • A Toolbox – a set of prefabricated, rapidly integrated software components.
    It means writing less code, with less risk of error. It also means greater productivity and the ability to devote more time to doing those things which provide greater added value, such as managing guiding principles, side effects, etc.
  • A Methodology – an “assembly diagram” for applications. A structured approach may seem constraining at first. But in reality it allows developers to work both efficiently and effectively on the most complex aspects of a task, and the use of Best Practices guarantees the stability, maintainability and upgradeability of the applications you develop.

There are a lot of solid PHP frameworks on the market, so it is probably hard to choose one. We have gathered a list of the best PHP frameworks currently on the market and share our insights in finding the best one for your application. Every framework has its own advantages as well as disadvantages, so if you have a preferred Framework by which you work with aside from the ones listed here, please do let us know by dropping us your feedback in the comment section below.

1. Laravel : The PHP Framework for Web Artisans

Laravel - Best PHP Framework 2014

Laravel is a free, open source PHP Web application framework, designed for developing MVC web applications. In our opinion, Laravel is the best overall PHP framework of 2014. I personally believe that Laravel has taken PHP frameworks to the whole new level. Laravel helps you create wonderful applications using simple, expressive syntax, aiming to take the pain out of web development by easing common tasks, such as authentication, routing, sessions and caching. Laravel is well readable and well-documented that helps you speed up your coding. Laravel makes development easy and more creative for developers and lets them produce some outstanding result with it. With Composer you can manage all your application’s third-party packages, and works great on MySQL, Postgres, SQL Server, and SQLite.

Laravel uses the solid, tested components of the Symfony framework along with other popular packages to provide a modern framework that provides easy conventions, utilizes modern programming patterns and makes development a breeze.

Laravel has changed my life. The best framework to quickly turn an idea into product.

Maksim Surguy

Laravel reignited my passion for code, reinforced my understanding of MVC, and made development fun again!

Jozef Maxted

Laravel kept me from leaving PHP.

Michael Hasselbring

2. Phalcon

Phalcon the Fastest PHP Framework 2014

Phalcon is the fastest framework on the list. Built on C, but offered as PHP extension, it offers no compromise speed wise. It offers high performance and lower resource usage. There’s no need to learn or use the C Language, as the functionality is exposed as PHP classes ready to use. By creating a rich, fully featured framework written entirely in C and packaged as a PHP extension, Phalcon is able to save processor time and boost overall performance.

In the past, performance was not considered one of the top priorities when developing web applications. Reasonable hardware was able to compensate for that. However when Google  to take site speed into account in the search rankings, performance became one of the top priorities alongside functionality. This is yet another way in which improving web performance will have a positive impact on a website.

3. Symfony 2

Symfony2 PHP Framework

Symfony is a PHP framework for web projects. It speed up the creation and maintenance of your PHP web applications. Replace the repetitive coding tasks by power, control and pleasure.

Symfony is a set of reusable PHP components and a PHP framework for web projects. It is well documented, it is free under MIT license, and it is getting more and more popular every day. Drupal, one of the most popular CMS systems, as well as phpBB, one of the most used discussion board system, use symfony.

The is powerful, scalable and flexible. Yet it is considered by many, especially those new to frameworks, to have a very steep learning curve.

This is true to a certain extent. At first glance, Models, Views, Controllers, Entities, Repositories, Routing, Templating, etc, altogether can appear very terrifying and confusing.

However, if you have grasped the fundamentals of PHP and HTML, have a basic understanding of modern web site development (in particular, Pretty URIs, MVC), and know how to CRUD a database/table, you are not far from developing a fairly good website, be it for your personal usage or business application.

4. Yii Framework

Yii PHP Framework

Yii is the fast, secure and professional PHP Framework. It is a high-performance PHP framework best for developing Web 2.0 applications. Yii Comes with rich features: MVC, DAO/ActiveRecord, I18N, caching, authentication and role-based access control, scaffolding, testing, open source, high performing, object oriented, database access object, easy form validation, default support for web services and many more. Yii Framework is ideal and perfect for developing social networking websites reduces development time significantly.

Yii Framework is a good choice for developing new high quality web-applications in rapid time. The well designed foundation with excellent documentation helped us developing Chives remarkable user experience and functionality in very short time.

David Roth

Yii Framework met all our needs! It worked equally good for both rapid prototyping and large scale web applications. It allowed us to focus on our unique idea while still offering the flexibility to bend our application in all directions we want.

Knut Urdalen

Yii is a simple but very powerful application framework with a very short learning curve. Its component-based design allows us to customize it for our needs without directly modifying it — maintaining upgradability. It’s amazing how we were able to use it not just on our main app and our API, but also on our daemons!

Blue Jayson

 

5. CodeIgniter

CodeIgniter PHP Framework

CodeIgniter is a proven, agile and open PHP web application framework with a small footprint. It is powering the next generation of web applications.

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.

CodeIgniter is right for you if:

  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need clear, thorough documentation.
  • You are not interested in large-scale monolithic libraries.
  • You need broad compatibility with standard hosting.
  • You prefer nearly zero configuration.
  • You don’t want to adhere to restrictive coding rules.
  • You don’t want to learn another template language.
  • You prefer simple solutions to complexity.
  • You want to spend more time away from the computer.

6. Cake PHP

Cake PHP Framework

CakePHP is one of the frameworks to follow in 2014. They are about to release a stable version 3.0 to the public. CakePHP makes building web applications easier, faster, and requires less code. It enabled to use code generation and scaffolding features to rapidly build prototypes. No additional XML or YAML file configuration is required, just setup your database and you are ready to bake. CakePHP is licensed under the MIT license which makes it perfect for use in common applications. The things you need are built-in: translations, database access, caching, validation, authentication, and much more are all built into one of the original PHP MVC frameworks. CakePHP comes with built-in tools for input validation, CSRF protection, Form tampering protection, SQL injection prevention and XSS prevention, helping you keep your application safe and secure.

7. Zend Framework

Zend PHP Framework

I’ve used Zend Framework 1 and 2 in large scale enterprise projects for years. It has been one of the leading PHP frameworks with flexible architecture suitable for modern web applications for years. Recently I have switched over to a couple of newborn frameworks, but that is my personal preference.

Zend framework is designed with simplicity in mind. It is lightweight, easily customizable, and focused on most common needed functionality. It is built to dramatically ease the learning curve you must climb when adapting to a new framework. It is widely used, so quite well tested and safe.

Despite all the advantages, it is has quite different user experiences over the years. Some users call it “extremely complicated, the worst I have known so far”.

Extremely complicated framework, the worst that I have known so far (I have worked with symfony, Yii and django; all them are easier to learn)

Great framework with a great community and a lot of tutorials…nearly everything is good, just the speed could be better.

ZF is overly complicated. At some point you will find yourself struggling with it just to make things done. Syntax is too lengthy.
I’d say ZF is a great PHP class library but an awful web framework.

8. Kohana

Kohana PHP Framework

Kohana is an elegant PHP framework with a rich set of features for building web applications. It allows to build web applications quickly, as it has many common components included, as translation tools, database access, code profiling, encryption, validation, and more. It also has good debugging and profiling tools which helps to solve any occurring problems, which often is very time-consuming without the right tools.

Kohana is built to be a very fast PHP framework, carefully optimized for real world usage. However, some of the tests shown that it is slower than CodeIgniter, and some other major players on the list. But in general, it scores very well on benchmarks.

This is an OOP framework that is very dry. Everything is build using strict PHP 5 classes and objects. This shows that Kohana is sticking to the very best of PHP new features and is closely optimizing its core code.

9. Fuel PHP

Fuel PHP Framework

Fuel is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks. It is currently releasing version 2 of the project, currently in beta stage.

FuelPHP is a MVC (Model-View-Controller) framework that was designed from the ground up to have full support for HMVC as part of its architecture. But we didn’t stop there, we also added ViewModels (also known as presentation models) into the mix which give you the option to add a powerful layer between the Controller and the View.

FuelPHP also supports a more router based approach where you might route directly to a closure which deals with the input uri, making the closure the controller and giving it control of further execution.

10. Silex

Silex PHP Framework

Silex is the PHP micro-framework based on the Symfony2 Components.

Silex is a PHP micro-framework for PHP 5.3. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra.

A microframework provides the guts for building simple single-file apps. Silex aims to be:

Concise: Silex exposes an intuitive and concise API that is fun to use.
Extensible: Silex has an extension system based around the Pimple micro service-container that makes it even easier to tie in third-party libraries.
Testable: Silex uses Symfony2’s HttpKernel which abstracts request and response. This makes it very easy to test apps and the framework itself. It also respects the HTTP specification and encourages its proper use.

Performance benchmark of the best PHP frameworks

There are many assumptions around performance of different PHP frameworks. I frequently hear strong opinions about superiority X over Y in this context. There are companies writing new PHP frameworks from scratch because available solutions are too slow for them. Let’s see what the number are telling.

Performing a representative benchmark across different framework is not an easy task. There are multiple ways to use each of them. Every use case will give different reading. Lets take routing as an example. Zend Framework 1 by default doesn’t need a routing file. It’s happy to use “/controller/action” pattern. On the other hand Symfony2 comes with a routing configuration. The file has to be read and parsed. That obviously takes some additional CPU cycles but does it mean Symfony2 routing is slower then Zend Framework 1? The answer is (obviously) no.

Systemarchitect has benchmarked “quick start” projects. That gives some idea on what is the base line for every framework and makes it possible to reproduce my tests (and argue against them).
Code was hosted on Amazon EC2 medium instance. I installed PHP-APC to avoid disk access and code parsing. I also made sure there is no I/O on Apache2 or application level. I set logs and cache paths to “/dev/shm/”. I tweaked projects to make them return roughly the same amount of data (10KB). All virtual hosts had the same mod_rewrite rules. AllowOveride was set to None.

Requests per second from Apache Benchmark with c=20 and n=500.

FrameworkReq/Sec
Phalcon822.96
Slim399.83
Kohana217.34
Code Igniter187.78
Silex179.01
Laravel135.9
YII123.5
Fuel PHP116.34
Hazaar MVC103.53
Zend Framework 1103.02
Cake PHP54.97
Nette53.48
Symfony239.22
Zend Framework 236.1

PHP Framework Benchmark 2014

Based on Systemarchitect’s benchmark, I’m not surprised, Phalcon is beating everyone on the list, as well as seeing Slim to be the second fastest because it’s a micro framework. The Quick Start project didn’t use any templates or layout which obviously contributed to the reading. Zend Framework 1 is twice faster than Symfony2 and Zend Framework 2 but in my experience the number will quickly go down in a real live setup.

Frameworks should speed up development, performance is a secondary concern. Zend Framework 2 and Symfony2 could do better but it’s not bad. There are ways to improve those numbers on production servers. Don’t reinvent the wheel, learn and use frameworks. There are various options which balance between performance and features.

Acumen’s summary

Summarizing the list, we think that the best 5 PHP Frameworks currently are: Laravel, Phalcon, Symfony2, CodeIgniter and Yii.

The same is shown by the recent study at Sitepoint, showing Laravel having over 25% of the popularity votes, Phalcon almost 17%, Symfony2 over 10%, CodeIgniter and Yii having 7.62%. PHP Framework Market Share 2014

But we understand that a PHP framework is more of a preference for the web developer and that in the market today there are many strong products.

Magento Template 

There are a lot of ways to add a new template to Magento. Adding a CMS Page Template in Magento, however, is a pretty simple process. Using the following configuration on your /app/etc/local.xml file in the “global” section will add a template to your CMS Page Design tab:

<cms>
    <layouts>
        <redirect>
            <label>Homepage Template</label>
            <template>page/home.phtml</template>
        </redirect>
    </layouts>
</cms>

Configuration Example

Magento template

Magento Template

Example of Page Edit

magento template

 

To learn more about basic software, visit the Wikipedia page below:

https://en.wikipedia.org/wiki/Software

WordPress

Our WP development team ran into a problem with the Media File Manager plugin by Atsushi Ueda in which the code was attempting to read from an array index that did not exist. This resulted in a Notice level error from PHP, and thus broke the file manager.  We think this utility is very useful to our CMS development, so we investigated a fix.

WordPress

 

Here is the issue we ran into:
Notice: Undefined offset: -1 in /path-to-wordpress/wp-content/plugins/media-file-manager/media-relocator.php on line 236

Line 236 contains the following:
$dir1[$i]['thumbnail_url'] = mrelocator_path2url($dir . $dir1[$min_child]['name']);

Solution

Change this to the following to resolve the issue:
if (isset($dir1[$min_child])) {
$dir1[$i]['thumbnail_url'] = mrelocator_path2url($dir . $dir1[$min_child]['name']);
}

 

References

Keywords

WP, plugin, PHP, CMS development

For information about how Acumen can help with your Software needs, contact us today!

 

 

Our PHP development team encountered many situations where remote connections to mysql take 5 seconds to return responses.  In some cases, we’ve rebuilt servers after tearing our hair out.  This has happened on Windows, Linux, PHP, apache, WordPress, joomla, Zabbix, and so many cases it makes me want to scream.  Of course, people love to point to Windows as the problem.  Lots of other people say optimize mysql.  Others say to configure your long_query_time parameter and check the logs.  None of this matters, because it isn’t Windows, it isn’t Linux, it isn’t PHP, it isn’t apache, it isn’t WordPress, it isn’t Zabbix, and it isn’t an optimization issue.

It is a reverse DNS problem.  Not a DNS problem, a reverse DNS problem.  A reverse DNS problem on your mysql server.  Which is absurd.  Why on earth would mysql server check for reverse DNS?  Why?

Because mysql wants to look at the host name for GRANT lookups.  Jeez.  Who cares.  I’d rather just fail the security than have all my applications wait five or ten seconds for every operation.

Solution

You can do one of two things to fix this:

1. Work with your network administrator to create reverse DNS PTR records.  Maybe you can get this done, maybe you can’t.

1b.  Create a host entry in the hosts (/etc/hosts or c:\windows\system32\drivers\etc\hosts).  This is good for both forward and reverse DNS.  Just never forget that you made it three years from now when you rename servers.

2.  Configure mysql with skip-name-resolve as described here.  For people that can’t control their reverse DNS PTR records – or can’t get help having them configured – this is the best option.

Want to make this really crazy?  If you have a multiple subnet network work with multiple DNS servers for hundreds of domains and split-horizon DNS for internal networks, you may have the extra fun of configuring conditional forwards for reverse DNS.  If you want to know how to do that, just ask in the comments.  (It’s not hard, so google may have already helped you.  You just have to know you need it.)

My apologies that this is an unusually snarky post.  It’s only consumed 80+ hours cumulative of my life.

Keywords

MySQL, PHP Development

Very often, programmers come from a mathematical background where they have frequently dealt with operators and operations and but find it confusing to use these same terms in the context of programming. I had that problem one time myself. Since then, I have spoken of how the methods of a class are operations upon the data of a class and been asked to define the term, even though I should have recognized the uncertainty that the term brings to discussions and preemptively addressed it myself.

In the context of computers, on definition of operation is the execution of one computer instructions. These instructions, or collections of instructions, usually manipulate one or more pieces of data. For example, one instruction might load the integer value stored in a memory location into a registry of the processor. Another instruction might load another integer into another memory location. A third instruction may add the two values together and store the sum in yet a third register. A fourth instruction may place the calculated value in to one of the first two memory locations, or place it in yet another memory location. When programmers talk about operations, they are ordinarily talking about a collection of fundamental processor operations that do something identifiable. Even very simple things like multiplication (a logical, programmatic operation) may take many processor operations from the standpoint of the processor.

In common usage of the term operation, we are not referring to individual atomic processor instructions, but the overall activity of a function or a line of code. For example, if we have the following code:

1. Dim I, j, k as Integers

2. I = 1

3. J = 1

4. k = I + j

Lines 2 and 3 each have 1 operation. In each of these lines, the value of 1 is copied into the memory locations named I and j. The equals sign is the assignment operator that takes the value of the expression on the right side of the equals sign (the value 1 on both lines) and copies it to the storage location identified (by friendly name, not by memory address) to the left of the equals sign (or assignment operator). It may take more than one computer instruction to execute these instructions, but we as programmers view it as a single operation.

Line 4 has two operations. There is an operation that adds I and j together, and another operator that assigns the result to the memory address (identified by the variable k) to the left of the equal sign. The plus sign is an operator that takes two integers and adds them together. The plus sign is also used as an operator for other data types, but if I and j are not types that the plus sign recognizes as types that the plus sign can use in any operation, an error will result at compile time. The equals sign is again recognized as the assignment operator.

We say that the plus sign operates on I and j, and the equals sign operates on the result of I and j (stored as an intermediate result in a register) as well as k.

So when we say that a method DoSomething(int I, int j) is an operation of the class which contains it, we are saying that DoSomething is a function that operates on I and j (and other variables that may be visible within its scope).

n operator is merely a shorthand way of representing common functions. For example, instead of writing k = I + j, most languages would let us have a function that operates on I and j that might look something like k = i.Add(j).

OneLogin is a great service that allows companies to use Single Sign On to allow their employees or customers to access a multitude of other applications using a single username and password. We are currently using it to do just that for a client – allow their customers to sign into their WordPress platform and other linked applications using just its authentication. Once the user is in WordPress, we can use the Embedded API and the Launch API offered by OneLogin give them a customized portal that utilizing single signon. Here’s how we did it on a high level.

Solution:

  1. Configure your application and your users. To attach an application to a user, open up your app.onelogin.com interface. In the top taps, go to “People”. Click “edit” next to the user you wish to add an application for. Then, to go to “Apps” tab for that person and click “add app“.
  2. Get the Embedded API security token. This can be found at https://app.onelogin.com/embedding. Check the “Embedding API can be used” checkbox and submit the form. If a token isn’t shown, click “Generate a new token“.
  3. Download and parse the apps XML file from OneLogin. The endpoint for this is https://app.onelogin.com/client/apps/embed2?token={security token}&email={email for requested user}
  4. Use the ID from the parsed XML to create a Launch API link. The URL for a Launch API link is https://app.onelogin.com/launch/{app id}

All you need to do is supply your security token to the class, pass the email to get_apps_for_user() function, and pass your HTML templates to the toHtml() function. The example on that GitHub page will show you how to use this inside of WordPress. Feel free to comment if you have questions or comments.

 

Want to see what kind of website or WordPress integrations we can offer your company? Check out our Website Development page and contact us!

PHP

Getting Started

This tutorial assumes you have the following applications installed:

PHPTools for Visual Studio

DEVSENSE has developed a fascinating plugin for Visual Studio – PHPTools. This plugin supplies IntelliSense and code completion, function definitions and documentation, as well as the ability to debug PHP – all inside of Visual Studio 2012.

Download the PHP Tools trial for free for 30 days to get started. Once it is installed, restart your Visual Studio project.

Creating and Debugging a Solution in Visual Studio

To create a project, go to FILE -> New Project… and select “PHP Web Project” under Templates -> PHP (image: http://d.pr/i/dQeq). Let’s start with some basic PHP for us to debug:

NewProject

< ?php

class Car {
    private $make;
    private $model;
    private $year;

    public function __construct($make, $model, $year) {
        $this->make = $make;
        $this->model = $model;
        $this->year = $year;
    }
    
    public function render() {
        echo $this->year . " " . $this->make . " " . $this->model;
    }
}

$mustang = new Car("Ford", "Mustang", 2002);
$mustang->render();

?>

Now, let’s set a breakpoint on line 19 and press the “Start” button in Visual Studio to debug and let’s see what happens.

Start

Hitting “Start” will allow Visual Studio to hook into your local HTTP server (Apache) and XDEBUG (an extension installed by XAMPP) to allow you to debug (you will see “?XDEBUG_SESSION_START=1” in the URL).

So now they we’ve started debugging, we quickly hit the breakpoint we set. If you right-click $mustang and click “Add Watch”, you can see the value of $mustang. At line 19, it is has not yet been set.

AddToWatch PHP

Press F10 to go to the next line – you will see in your Watches window that we now have a Car object.

Watch1

While on line 20, press F11 to step into the Car->render() function. We can see that the code ready to echo out the variables. Press “Continue” to finish the script and the result will display in your browser.

BrowserDisplay

You have now successfully debugged a PHP script in your browser! This approach can be taken with many applications – including WordPress

See our CMS Web Development Page for more ways we can help you!