Re: [PHP] OOP Newbie - why does this not work?

2005-10-21 Thread Jesper Gran

On 2005-10-21 06:17, Stephen Leaf wrote:


most likely var is depreciated in php5. (can someone confirm this?)
 


Well, if I try to use Var in a class i get this message:

Strict Standards: var: Deprecated. Please use the 
public/private/protected modifiers in C:\code\test\var.php on line 3*


/*Jesper*
*

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP Newbie - why does this not work?

2005-10-21 Thread Jochem Maas

Bob,

'wrapping' you class definition within HTML like you have done is
not only weird but down right ugly. I recommend sticking each class
you write in a seperate file and using include_once() or require_once()
before you output anything to the browser. basically try to
seperate you code into 'stages' (for want of a better word) e.g.:

1. setup an environment (includes loading classes)
2. process the request
3. redirect or output a page

Bob Hartung wrote:

Hi all,


...



/head
body
br
  PThis is outside the php code block/P
br
?php
  echo Start defining the class here: BR ;
/*  class Test
  {

function __constructor()

 {
   var $saying ;


'var' doesn't belong here. it belongs directly in the body of class def.


$saying = Im in the Test Class ;
 }
   
 function get()

 {
   return $saying ;



there is a missing '}' here.
also you should be returning and setting $this-saying


   
  }

  var $liveclass ;


drop the 'var' - it's only for php4 and then only for
defining the properties of classes/objects:

class Test {
var $myProperty;
}


  $liveclass = new Test ;
  echo $liveclass-get() ;
  echo BR ;
 echo This is in the php code block ;
*/
?

/body
/html



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP Newbie - why does this not work?

2005-10-21 Thread Stephen Leaf
would have to be.

http://smileaf.org/bob.php

as you can see it's working great.

did make  few more changes:
class Test {
public $saying = ;

function __construct() {
$this-saying = I'm in the Test 
Class. ;
}
function get() {
return $this-saying ;
}
}

when accessing a class variable _always_ in php use $this-

On Friday 21 October 2005 04:42 am, Bob Hartung wrote:
 Stephen,
I copied your code and ran it.  Same thing - a totally blank page.
 Therefore I have to surmise that there is a a) bug in the rpm I
 downloaded or more likely b) I have a conf setting wrong.  I will
 investigate further -- boy oh boy what a way to start!  Every line of
 code is a new chance to learn.

 Thanks again,

 Bob

 snip all before 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP Newbie - why does this not work?

2005-10-20 Thread Stephen Leaf
Try removing the /* and */
Other than that, check your brackets.
you never closed the get() function's

On Thursday 20 October 2005 09:35 pm, Bob Hartung wrote:
 Hi all,
I'm trying to get started in OOP with PHP.  I have the following
 short code snipped.  I'f I comment out the 'class Test' definition and
 the following references to it, it prints
 This is outside the php code block

  and

 Start defining the class here:

 If I do not comment out the code as noted, then the page returned is
 totally blank.  It does this with or without using the constructor.
 PHP 5 on apache.  Same behavior both on Win32 and FC4.

 All help appreciated to get me going.

 Code Snippet:

 html

 head
titlePHP Class testing/title

 /head
 body
   br
 PThis is outside the php code block/P
   br
   ?php
 echo Start defining the class here: BR ;
 /*  class Test
 {

   function __constructor()
{
  var $saying ;
   $saying = Im in the Test Class ;
}

function get()
{
  return $saying ;

 }

 var $liveclass ;
 $liveclass = new Test ;
 echo $liveclass-get() ;
 echo BR ;
   echo This is in the php code block ;
 */
   ?

 /body
 /html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP Newbie - why does this not work?

2005-10-20 Thread Stephen Leaf
Sorry.. 1 more thing.
php5 does not use var.
use public $variable=value; instead.
public is only within a class however. you cannot use it outside.

On Thursday 20 October 2005 09:35 pm, Bob Hartung wrote:
 Hi all,
I'm trying to get started in OOP with PHP.  I have the following
 short code snipped.  I'f I comment out the 'class Test' definition and
 the following references to it, it prints
 This is outside the php code block

  and

 Start defining the class here:

 If I do not comment out the code as noted, then the page returned is
 totally blank.  It does this with or without using the constructor.
 PHP 5 on apache.  Same behavior both on Win32 and FC4.

 All help appreciated to get me going.

 Code Snippet:

 html

 head
titlePHP Class testing/title

 /head
 body
   br
 PThis is outside the php code block/P
   br
   ?php
 echo Start defining the class here: BR ;
 /*  class Test
 {

   function __constructor()
{
  var $saying ;
   $saying = Im in the Test Class ;
}

function get()
{
  return $saying ;

 }

 var $liveclass ;
 $liveclass = new Test ;
 echo $liveclass-get() ;
 echo BR ;
   echo This is in the php code block ;
 */
   ?

 /body
 /html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OOP Newbie - why does this not work?

2005-10-20 Thread Stephen Leaf
Here is the working code
You had __constructor() it's __construct()

notice I also moved your saying declaration outside of the constructor.
this is to make it a class level variable.
the way that you had it set it was only in scope until you finished the 
construct code.

I guess I was wrong about the var bit. I do remember having lots of issues 
with it back a few months ago. perhaps theses were fixed in newer versions.
most likely var is depreciated in php5. (can someone confirm this?)

html
head
titlePHP Class testing/title
/head
body
br/
pThis is outside the php code block/p
br/
?php
echo Start defining the class here: br/ ;
class Test {
public $saying = ;

function __construct() {
$saying = Im in the Test Class ;
}
function get() {
return $saying ;
}
}

$liveclass = new Test ;
echo $liveclass-get() ;
echo br/ ;
echo This is in the php code block ;
?
/body
/html


On Thursday 20 October 2005 09:53 pm, Bob Hartung wrote:
 Changed to:
var $saying ;
public $saying = .

 Again, blank page.  Funny though, even the title.../title html block
 is not rendered.  Again, same beavior on 2 FC4 and 1 Win32 install.

 Tnx

 Bob

 Stephen Leaf wrote:
  Sorry.. 1 more thing.
  php5 does not use var.
  use public $variable=value; instead.
  public is only within a class however. you cannot use it outside.
 
  On Thursday 20 October 2005 09:35 pm, Bob Hartung wrote:
 Hi all,
I'm trying to get started in OOP with PHP.  I have the following
 short code snipped.  I'f I comment out the 'class Test' definition and
 the following references to it, it prints
 This is outside the php code block
 
  and
 
 Start defining the class here:
 
 If I do not comment out the code as noted, then the page returned is
 totally blank.  It does this with or without using the constructor.
 PHP 5 on apache.  Same behavior both on Win32 and FC4.
 
 All help appreciated to get me going.
 
 Code Snippet:
 
 html
 
 head
titlePHP Class testing/title
 
 /head
 body
 br
   PThis is outside the php code block/P
 br
 ?php
   echo Start defining the class here: BR ;
 /*class Test
   {
 
 function __constructor()
  {
var $saying ;
 $saying = Im in the Test Class ;
  }
 
  function get()
  {
return $saying ;
 
   }
 
   var $liveclass ;
   $liveclass = new Test ;
   echo $liveclass-get() ;
   echo BR ;
   echo This is in the php code block ;
 */
 ?
 
 /body
 /html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php