Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.php > #3228

Re: New to OOP in PHP

Newsgroups alt.php
Date 2020-03-16 04:38 -0700
References <4ea175e5-f5ff-4bdc-b36e-82990c76b3e9@a12g2000vbz.googlegroups.com>
Message-ID <7d127fd5-a2da-4ce0-aff2-19409161008d@googlegroups.com> (permalink)
Subject Re: New to OOP in PHP
From robamman2020@hotmail.com

Show all headers | View raw


Your code seems interesting...

Kristjan Robam

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
> 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

Back to alt.php | Previous | NextNext in thread | Find similar


Thread

Re: New to OOP in PHP robamman2020@hotmail.com - 2020-03-16 04:38 -0700
  Re: New to OOP in PHP Allodoxaphobia <trepidation@example.net> - 2020-03-17 16:26 +0000
    Re: New to OOP in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-19 10:02 -0700

csiph-web