[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Error : Connot Access Empty Refrence

Posted on 2007-11-17
5
Medium Priority
?
337 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
3 Comments
 
LVL 1

Accepted Solution

by:
Zibings earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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