You are here: Re: Object Oriented PHP « PHP Programming Language « IT news, forums, messages
Re: Object Oriented PHP

Posted by Jerry Stuckle on 10/14/61 11:51

Jim Carlock wrote:
> "Tony Marston" <tony@NOSPAM.demon.co.uk> and
> "Jerry Stuckle" <jstucklex@attglobal.net> argued a bunch
> about objects, their encapsulated data, and how events
> change the nature of the object...
>
> I'm curious as to what the simplest object oriented program
> in PHP would be. Either one of you that might be able to
> suggest something or provide a demonstration?
>
> Thanks.
>

Let's see.. It would be one object with a single attribute and one method. The
program would just need to create an object of

Here's one with a a couple of functions to do something useful. It formats the
current date according to "US" or "European" standards and remembers the format.
Note it can be easily expanded to include other date functions and formats.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Simple date display</title>
<?php
class Date {
private $format = 'm/d/Y';

function setFormat($format) {
switch($format) {
case 'US':
$this->format = 'm/d/Y';
return true;
case 'European':
$this->format = 'd.m.Y';
return true;
}
return false;
}
function today() {
return date($this->format);
}
}
?>
</head>
<body>
<?php

$date = new Date();
echo 'Date in U.S. format: ' . $date->today() . "<br>\n";
$date->setFormat('European');
echo 'Date in European format: ' . $date->today() . "<br>\n";
?>
</body>
</html>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация