Solved

PHP Error : Connot Access Empty Refrence

Posted on 2007-11-17
5
318 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now