Solved

PHP Error : Connot Access Empty Refrence

Posted on 2007-11-17
5
320 Views
Last Modified: 2008-10-10
Hello. I am not familiar with PHP. I have an error: Connot Access Empty Refrence.
My Code is:

<?php
      class Student{
            var $name;
            function Student($n){
                  $this->$name = $n;
            }
            function sayHello(){
                  $
print $this->$name";
            }
      }
      $std1 = new Student("reza");
      $std1->sayHello();
?>

Help please.
0
Comment
Question by:Tech_View
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Zibings earned 500 total points
ID: 20303747
You'll want to clean up your code a little bit.  You needn't use the $ in front of your property name to access it with $this.  Here's how it might work better for you:
<?php
 
  class Student {
    var $name;
    function Student ( $n ) {
      $this->name = $n;
    }
    function sayHello ( ) {
      print $this->name;
    }
  }
 
  $std1 = new Student("reza");
  $std1->sayHello();
 
?>

Open in new window

0
 

Author Comment

by:Tech_View
ID: 20338691
I will try it ....
0
 

Author Comment

by:Tech_View
ID: 20520790
I still have an error, maybe my mistake, I will try again....
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question