Web Applications

PHP Language

Objectives

  • Exercise: ShoppingCart
  • Exercise: Arrays and iterators
  • Exercise: Factory
  • Exercise: Proxy

Running PHP

Now is not the time to install PHP!

There is PHP interpreter available at lab computers.

You may have php installed locally or run using an online sandbox (onlinephp.io, onecompiler.com, ... ).

Before the next exercise ...

Exercise: ShoppingCart

Copy content PHP code. Add code so the file can be executed and produce the desired output.

The objective is to implement a simple class for a shopping cart.

Do not be afraid of the magic, __toString.

Before the next exercise ...

Exercise: Arrays and iterators

Copy PHP code. Add code so the file can be executed and produce the desired output. The objectives are:

  • Allow content access in an array-like fashion.
  • Allow for foreach iteration.

Before the next exercise ...

Exercise: Factory

Copy PHP code. Add code so the file can be executed and produce the desired output.

The objective is to provide a user of the User class with the ability to save the class content into a JSON and a string. Implement the Writer interface and create writer for String and JSON. Implement a factory method (createWriter) for those classes.

You may need json_encode.

Before the next exercise ...

Exercise: Proxy

Extend existing PHP code. Modify code so the file can be executed and produce the desired output.

The objective is to monitor invocation of class methods.

Exercise: Proxy II.

Let's get real, we can do better. The proxy implementation has several issues:

  • There was no test for the proxy functionality.
  • We can not proxy printStatistics method.
  • There were not enough language features used.

Time to be fancy. Here is the PHP code, you already know what to do.

How are we doing?

  • Exercise: ShoppingCart
  • Exercise: Arrays and iterators
  • Exercise: Factory
  • Exercise: Proxy
Questions, ideas, or any other feedback?

Please feel free to use the anonymous feedback form.