Web Applications

PHP Language

Objectives

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

Running PHP

There is PHP interpreter available at lab computers. Works like a Python interpreter.

You may have php installed locally (do not install now!) 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.

Consider use of __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, ucfirst.

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. There are two difficulty levels.

How are we doing?

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

Leave an anonymous feedback.

Questions, ideas, or any other feedback?

Please feel free to use the anonymous feedback form.