Solved

PHP Error : Connot Access Empty Refrence

Posted on 2007-11-17
5
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 look for a specific file type in a local or remote server directory using PHP.

690 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