Question

I can't acces to the variable create un a specific file and using by another link by a third one.
Here is an example, I have 3 files:
testing.php

<?php 
$special ="foo";
?>

other.php

<?php
echo $special; // that works

class Testing
{
   public function toto()
   {
     echo $special;//Error considering as undefined
   }
}
?>

main.php

<?php
require 'testing.php';
echo "require work $special";// that works
require 'other.php';

$a = new Testing();
$a->toto();//error
?>

So how can i acces to my variable $special in the member of my class Testing.

Was it helpful?

Solution

The $special variable is not visible from within the function. For that to work, you need to pass the function the $special variable as an argument when you call it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top