Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6053157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:00:30+00:00 2026-05-23T08:00:30+00:00

Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I have reduced this

  • 0

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

I have reduced this error down to the smallest amount of code and it is so small, that I really feel stupid here.

I have 2 files class1.php :

  1 <?php
  2 class insertText{
  3         //properties
  4         protected $paragraph1='<p>this is a test paragraph</p>';
  5         protected $bigHeader='<h1>header1</h>';
  6         protected $textArray;
  7
  8         public function __construct () {
  9                 $this->$textArray = array($this->$bigHeader1, $this->$paragraph1);
 10         }
 11         public function getText(){
 12                 return $this->$textArray;
 13         }
 14 }
 15 ?>

and test.php:

1 <?php
2 include './class1.php';
3 echo "Begin\n";
4
5 $filler = new insertText();
6 echo $filler->getText();
7
8 echo "end\n";
9 ?>

When I run:
$ php text.php

Begin
PHP Notice:  Undefined variable: bigHeader1 in class1.php on line 9
PHP Fatal error:  Cannot access empty property in class1.php on line 9

I know that this has te be an easy answer, and I did search and search every post with either error message. I even tried moving the assignment of text to the variables to within the constructor and it dodn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:00:31+00:00Added an answer on May 23, 2026 at 8:00 am

    You need to use:

    $this->textArray = array($this->bigHeader1, $this->paragraph1);
    

    …instead of..

    $this->$textArray = array($this->$bigHeader1, $this->$paragraph1);
    

    i.e.: The second dollar symbol in $this->$bigHeader1 is redundant. (You’re in effect attempting to access a class element that would be defined within the $bigHeader1 variable, as opposed to the class instance variable itself.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am just learning
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am new to
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” All of a sudden
Possible Duplicate: PHP: the ultimate clean/secure function I have got this code when I
Possible Duplicate: php headers already sent error I have attached my code which am
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of
Possible Duplicate: PHP: Date larger than current date I have my dates in this
Possible Duplicate: php scandir --> search for files/directories I have a folder, inside this
Possible Duplicate: Undefined Index when using post I'm a beginner php developer and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.