Include php script into php class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mellice
Forum Newbie
Posts: 1
Joined: Wed Feb 10, 2010 6:45 am

Include php script into php class

Post by mellice »

Hi there,
I've a php script in certain file called a.php, contains php script:
<?
$variable1 = 'hello world';
?>

Now I have a php class in other file named b.php, and I want to access the $variable1 into a method in this class

how can I do this?

thanks
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Include php script into php class

Post by aravona »

mellice wrote:Hi there,
I've a php script in certain file called a.php, contains php script:
<?
$variable1 = 'hello world';
?>

Now I have a php class in other file named b.php, and I want to access the $variable1 into a method in this class

how can I do this?

thanks
It should work using this:

Code: Select all

 
<?php
include("b.php");
$variable1 = 'hello world';
?>
Or

Code: Select all

 
<?php
include("a.php");
//your b file coding
?>
http://php.net/manual/en/function.include.php
Post Reply