PHP


PHP Support

Ob_flush , ob_start ,ob_get_contents, ob_end_clean, ob_end_flush with real time example

Let see the Functions first then will see the real world example

ob_start is to start buffer the output 

ob_flush is to flush the buffered output (that means it will delivers the output here which is buffered when the ob_start is initiated)

ob_end_flush is to flush and ends the buffering

ob_end_clean is to clean the buffered output content ends the buffering

ob_get_contents is to get the buffered output content

 

Mediator Pattern simple design Example

Mediator Pattern  Example in PHP  


Let me tell you, Design patterns are some patterns that were used and implemented in many projects for reusability of the code, specific to some logics and concepts, which were successfully achieved the purpose.

So now programmers are implementing the design patterns for their projects.

Say for example mediator pattern is used to communicate effectively between the classes.

Say in other ways

Ram Memory Usage

Snippet to detect the memory usage on your server in php

echo "Initial: ".memory_get_usage()." bytes \n";
/* prints
Initial: 361400 bytes
*/

// let's use up some memory
for ($i = 0; $i < 100000; $i++) {
	$array []= md5($i);
}

// let's remove half of the array
for ($i = 0; $i < 100000; $i++) {
	unset($array[$i]);
}

echo "Final: ".memory_get_usage()." bytes \n";
/* prints
Final: 885912 bytes
*/

echo "Peak: ".memory_get_peak_usage()." bytes \n";
/* prints
Peak: 13687072 bytes
*/

 

PHP Traits vs Interfaces OOPS use usages

Traits in php, Its having some default definition, let It be there, Now According to me its just to support multiple inheritance 

Say for example I'm Implementing a interface in class 

interface someinterface {
  public function somefunction();

}

 

class A implements someinterface {

  public function somefunction()  {

  }
}

This is an interface implements by class. 

Now See the below code. what do you think about it ?

PHP Traits vs Interface OOPS

Traits in php, Its having some default definition, let It be there, Now According to me its just to support multiple inheritance 

Say for example I'm Implementing a interface in class 

interface someinterface {
  public function somefunction();

}

 

class A implements someinterface {

  public function somefunction()  {

  }
}

This is an interface implements by class. 

Now See the below code. what do you think about it ?

How php compact function is usefull for mvc frameworks

<?php
$firstname = "Karthikeyan";
$lastname = "Manivasagam";
$age = "27";

$name = array("firstname", "lastname");
$result = compact($name, "location", "age");

print_r($result);
?>
Output 

Array ( [firstname] => Karthikeyan [lastname] => Manivasagam [age] => 27 )

How php compact function is usefull for mvc frameworks ? let me tell you

We could use the same method when we pass/set  variables to views in controller