PDA

View Full Version : [PHP] Variable changes by itself!



NeoDreamer
October 31st, 2007, 10:36 PM
In my constructor for my Flickr class, I set $baseURL to equal Flickr's folder for API calls. For some reason, $baseURL took on the value of $key without me doing anything!

index.php


<?php
include_once('Flickr.php');

$photos = new Flickr();
$userID = $photos->getUserID('fart');
?>

Abridged version of Flickr.php


function Flickr()
{
$this->$baseURL = 'http://www.flickr.com/services/rest/';
$this->$key = '123';
}


function getUserID($name)
{
echo 'base url: ' . $this->$baseURL . '<br />';

$url = $this->$baseURL . '?method=flickr.people.findByUsername' .
'&api_key=' . $this->$key .
'&username=' . $name;

echo 'url: ' . $url . '<br />';
}

When I run index.php


base url: 1234
url: 1234?method=flickr.people.findByUsername&api_key=1234&username=fart

hl
October 31st, 2007, 11:41 PM
I don't know if this is affecting it really, but you're supposed to declare class variables as $this->baseURL (no $). Try posting the nonabridged version, because I see nothing wrong as of yet.

NeoDreamer
October 31st, 2007, 11:52 PM
PROBLEM SOLVED!

You're completely right. My code is working now. Thanks.

This was the first time I ever did OOP in PHP.... :D