Warning: fopen(D:\Hosting\8718415\html\pavang/wp-content/plugins/gtranslate/install.log) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\8718415\html\pavang\wp-content\plugins\gtranslate\gtranslate.php on line 615

Warning: fclose(): supplied argument is not a valid stream resource in D:\Hosting\8718415\html\pavang\wp-content\plugins\gtranslate\gtranslate.php on line 616
Pavan Gudhe

PHP 5.4 Features

Published by Pavan in PHP on January 31st, 2012

Traits:

As we all know PHP doesn’t support multiple inheritance. However, PHP implements the support to have classes with multiple interfaces since v5.

You can define a trait practically the same way you define a class or interface with functions you need.

Traits do not provide state in the form of properties, but only an interpreter-assisted copy & paste of methods.

Traits have a conflict resolution mechanism, multiple traits can be used in the same class even if some method names are overlapping.

example:

<?php
class Base {
public function sayHello() {
echo 'Hello ';
}

trait SayWorld {
public function sayHello() {
parent::sayHello();
echo 'World!';
}
}

class MyHelloWorld extends Base {
use SayWorld;
}

$o = new MyHelloWorld();
$o->sayHello();
?>

 

Built-In Web Server:

PHP 5.4 is coming with a built in HTTP web server. Now you can test your applications on your local machine without having Apache or any other web server What you need is only PHP 5.4 installation.

Command to run PHP as Web Server:

$ php -S localhost:8000

Server is listening on localhost:8000... Press CTRL-C to quit.

 

Deprecations:

  • Magic quotes options have been deprecated.
  • PHP namespace is removed
  • E_STRICT errors, are now covered by E_ALL.

 

Function to Iterate through dates in Postgresql

Published by Pavan in PHP on November 7th, 2011

Its not a rocket science or something like that but may help some one to work with date iterations in PostgreSQL.

My requirement was to insert the back dated data into a table for days between two dates, the dates were fix eg. 05/01/2011 to 09/19/2011 so I decided to write a SQL Function. Well in my case there was specific reason to do this in SQL only one can do it using PHP Script also.

CREATE FUNCTION date_iterator() RETURNS SETOF typ_error_msg AS
$body$
DECLARE
lStartDate DATE;
lEndDate DATE;
lDays INTEGER;
BEGIN

lStartDate := TO_DATE(’05/01/2011′,’mm/dd/YYYY’);
lEndDate := TO_DATE(’08/01/2011′,’mm/dd/YYYY’);

FOR lDays IN 0..lToDate – lStartDate
LOOP
RAISE INFO ‘%’, lStartDate;
lStartDate := lStartDate + INTERVAL ’1 days’;
END LOOP;

END;
$body$
LANGUAGE ‘plpgsql’ VOLATILE CALLED ON NULL INPUT SECURITY DEFINER;

– TO CALL FUNCTION
SELECT * FROM date_iterator();
DROP FUNCTION date_iterator();

In PHP one can do it like this:

$dateStart = strtotime( ’05/01/2011′ );
$dateEnd = strtotime( ’08/01/2011′ );

do{

print_r( date( ‘m/d/Y’, $dateStart ) );

//code to manipulate

$dateStart = strtotime( “+1 day”, $dateStart );
}while( $dateStart <= $dateEnd );

© Pavan Gudhe
Twitter Bird Gadget