Jump to content

New to PHP classes... variable errors?


StrangeWill

Recommended Posts

<?php
class Student
{
var $varName,
    $varPhone,
    $varTest;
function Student()
{
}
}
?>

<?php
$Kyle = new Student();
$Kyle->$varName = 'kyle';
$Kyle->$varPhone = 'phone number';
$Kyle->$varTest = 'test';
?>
Name: <?=$Kyle->$varName?>
<br />
Phone: <?=$Kyle->$varPhone?>
<br />
Test: <?=$Kyle->$varTest?>



All of them print 'test'

No matter what, it always prints the last variable entered! Gah!

Using PHP 4.4.2
Link to comment
https://forums.phpfreaks.com/topic/25975-new-to-php-classes-variable-errors/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.