Writing objects in PHP

It is now nearly 4 years on this time of writing since actively been using PHP in most of my web developments in my current workplace. Some old habits do not die as I am still inclined to writing codes sans Java.
java vs php


class Customer {

 private String name;
 private int age;

 public void setName(String name) {
  this.name = name;
 }

 public String getName() {
  return name;
 }
 // same can be done for age
}

The above is how we write in Java. Well when I first started PHP and when I first got to know PHP in college, there were no such things as object. It took me awhile to sink in that it was many years ago. Now with objects, the easier it is to pass my values to another function. It was dreadful thinking that one has to pass information using an array in those early days. Thank goodness for Objects (sort of like an array though).


public Class Customer {
 private $name;

 function setName($name) {
  $this->name = $name;
 }

 function getName() {
  return $this->name;
 }
}

Well, things still doesn’t change though. I find that with php, codes are still vulnerable if they get a hold of your server. Java though has been compiled in class files (harder to understand but definitely still able to).

Seems like technical is not only limited to just being an expert in one language. Just your everyday technical knowledge and learning etiquette.

Leave a Reply