Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New to OOP in PHP

19 views
Skip to first unread message

Karl-Arne Gjersøyen

unread,
Oct 22, 2011, 6:17:10 AM10/22/11
to
Hello.
I am new to OOP in PHP and am trying to lear me how to create classes
with property and methods in class files. Then include them in an
ordinary php file and use instance to create objects.

I have in my class file a property with default value. It is some
XHTML code. But I can't fine the reasons for why it not can be
displayed.
Here is my files.
First the ordinary PHP file with instance

(my_form.php)
---------------------
<?php
include('class_my_form.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml;
charset=utf-8" />
<title>My Form</title>
<meta name="generator" content="BBEdit 10.1" />
</head>
<body>
<h1>My Form</h1>
<?php
// Print form
// First get a new object
$myForm = new feedback();
// Save the Form code
$myForm->setHtml($form);
echo $myForm->Html;


//$name = "Karl-Arne";

// Create a new object
$n = new feedback($name);
// Save $name into $n->Name
$n->setName($name);

// Print to screen
echo $n->Name;

?>
</body>
</html>


And here is my class file
(class_my_form.php)
<?php
class feedback{
// Properties
private $name;
private $email;
private $subject;
private $message;
private $form = <<<HTML
<form action="my_form.php" method="post">
<p>
Name:<br />
<input type="text" name="name" />
</p>
<p>
<input type="submit" name="submit" value="Submit" />
</p>
</form>
HTML
;


// Methods
// Form
public function setHtml($form){
$this->Html = $form;
}
function getHtml(){
return $this->Html;
}

// Name
public function setName($name){
$this->Name = $name;
}
public function getName(){
return $this->Name;
}
}
?>

Can somebody explain what I am doing wrong here? I have try to use
var_dump() but it did not return anything to me.

Thanks.
Karl

Jerry Stuckle

unread,
Oct 22, 2011, 8:59:21 AM10/22/11
to
Turn on all errors and display them. Fix the messages you get.

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

robamm...@hotmail.com

unread,
Mar 16, 2020, 7:38:23 AM3/16/20
to
Your code seems interesting...

Kristjan Robam

Allodoxaphobia

unread,
Mar 17, 2020, 12:26:22 PM3/17/20
to
On Mon, 16 Mar 2020 04:38:21 -0700 (PDT), robamm...@hotmail.com wrote:
> laupäev, 22. oktoober 2011 13:17.10 UTC+3 kirjutas Karl-Arne Gjersøyen:
>> Hello.
>> I am new to OOP in PHP and am trying to lear me how to create classes
>
> Your code seems interesting...
>
> Kristjan Robam

Why the hell are you replying to 5, 6, 7, and 9 year old posts?

Oh, I see. It's a google grooper bored in self quarantine.

(top posting corrected)

Kristjan Robam

unread,
Mar 19, 2020, 1:02:08 PM3/19/20
to
I found something interesting for me ....
To be exact, this part: "private $form = <<<HTML
<form"



With best wishes,
Kristjan Robam
0 new messages