PHP Objects


PHP Objects: Like other programming languages Java,VB.Net,C# etc php also supports object oriented related concepts.Here we will learn classes and objects conceps in genenral.
Class is a blueprint for object creation and also we can say that object is a real world entity which has state and properties. For Example a bus class may contain speed ,color etc properties by which we can differentiate any other object from bus.
/p>


PHP Objects | Example

Before going deeper into php oops programming let us take a brief tour for oops concepts.

  1. Class
  2. Object
  3. Member Variable
  4. Member Function
  5. Inheritance

How to define PHP classes

Here is the example how to define and use simple class in php.

Example

<html>
<head>
<title></title>
</head>
<body>
<?php
class Hello {
	function myfun($arg1,$arg2) {
		$arg3 = $arg1 + $arg2;
		return $arg3;
	}

}
	$hello=new Hello();
	echo $hello->myfun( 12, 2);
?>
</body>
</html>

Advertisements

Add Comment

📖 Read More