[PHP] Problem with extending classes.

2005-05-13 Thread Shaw, Chris - Accenture

Hello,

Been playing around with classes in php5, extending a base class and using a
constructor etc..

But I seem to have a problem with getting the variables outside the class.
In test1.txt, I cannot anything when I access the public variables for the
class.

In test2, when I make $contact into $contactcontact, I get the values for the
variables, but it looks like all the variables in that class reference
$contactcontact when you try to access them outside the class.

Have I missed something or is there bugs with extending classes in php5?
Does this happen in php4.3?

Thanks for any help.

Chris.

 test1.txt  test2.txt




This message has been delivered to the Internet by the Revenue Internet e-mail 
service

*?php

class baseclass
{
public $name;
public $contact;
  
  function ksplit($text)
  {
echo br\nInside ksplit::;
$array = explode(':',$text);
echo $text,  - , $array[1];
return $array[1];
  }
}

class extendedclass extends baseclass
{
public $address;

function extendedclass($name, $contact, $address)
{
echo Extendedclass Entrybr\n;
echo $name,  - , $contact,  br\n, $address;
$this-$name = $this-ksplit($name);
$this-$contact = $this-ksplit($contact);
$this-$address = $this-ksplit($address);
echo br\nExtendedclass Exitbr\n;
echo $this-$name,  - , $this-$contact,  br\n, $this-$address;
}
}

$myclass = new extendedclass(Name:Bob, Contact:123456789, 
Address:abcdefghijklmnopqrstuvwxyz);

echo br\nOutside Classbr\n;
echo $myclass-$name,  - , $myclass-$contact,  br\n, $myclass-$address;

?

-HTML RESULTS---

Extendedclass Entry
Name:Bob - Contact:123456789 
Address:abcdefghijklmnopqrstuvwxyz
Inside ksplit::Name:Bob - Bob
Inside ksplit::Contact:123456789 - 123456789
Inside ksplit::Address:abcdefghijklmnopqrstuvwxyz - abcdefghijklmnopqrstuvwxyz
Extendedclass Exit
Bob - 123456789 
abcdefghijklmnopqrstuvwxyz
Outside Class
- 

?php

class baseclass
{
public $name;
public $contactcontact;
  
  function ksplit($text)
  {
echo br\nInside ksplit::;
$array = explode(':',$text);
echo $text,  - , $array[1];
return $array[1];
  }
}

class extendedclass extends baseclass
{
public $address;

function extendedclass($name, $contact, $address)
{
echo Extendedclass Entrybr\n;
echo $name,  - , $contact,  br\n, $address;
$this-$name = $this-ksplit($name);
$this-$contactcontact = $this-ksplit($contact);
$this-$address = $this-ksplit($address);
echo br\nExtendedclass Exitbr\n;
echo $this-$name,  - , $this-$contactcontact,  br\n, 
$this-$address;
}
}

$myclass = new extendedclass(Name:Bob, Contact:123456789, 
Address:abcdefghijklmnopqrstuvwxyz);

echo br\nOutside Classbr\n;
echo $myclass-$name,  - , $myclass-$contactcontact,  br\n, 
$myclass-$address;

?

--HTML RESULTS-

Extendedclass Entry
Name:Bob - Contact:123456789 
Address:abcdefghijklmnopqrstuvwxyz
Inside ksplit::Name:Bob - Bob
Inside ksplit::Contact:123456789 - 123456789
Inside ksplit::Address:abcdefghijklmnopqrstuvwxyz - abcdefghijklmnopqrstuvwxyz
Extendedclass Exit
Bob - 123456789 
abcdefghijklmnopqrstuvwxyz
Outside Class
123456789 - 123456789 
123456789 -- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] Problem with extending classes.

2005-05-13 Thread Kim Madsen

 -Original Message-
 From: Shaw, Chris - Accenture [mailto:[EMAIL PROTECTED]
 Sent: Friday, May 13, 2005 12:10 PM
 To: php-general@lists.php.net
 Subject: [PHP] Problem with extending classes.
 
 Have I missed something or is there bugs with extending classes in
php5?
 Does this happen in php4.3?

$this-$name = $this-ksplit($name);
$this-$contactcontact = $this-ksplit($contact);
$this-$address = $this-ksplit($address);

Regardless of inheriting or not it should be:

$this-name = $this-ksplit($name);
$this-contactcontact = $this-ksplit($contact);
$this-address = $this-ksplit($address);

--
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen
Systemudvikler/Systemdeveloper

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