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
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Thu Jun 17, 2004 7:08 pm
I'm using php 5 and I'm having this problem and I'm not sure if I'm the one that's wrong or php is not doing what is supposed to:
Code: Select all
<?
class editor {
static $pages = 'first';
function __construct () {
$this->pages = 'second';
}
}
$test = new editor;
echo editor::$pages; // prints 'first'
?>
Shouldn't it print second?
Am I wrong in assuming that it should print second?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Jun 17, 2004 7:11 pm
Code: Select all
<?php
<?
class editor {
static $pages = 'first'; // your missing a quote
function __construct () {
$this->pages = 'second';
}
}
$test = new editor;
echo editor::$pages; // prints 'first'
?>
?>
EDIT: YOU WERE missing a quote.. guess u edited it
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Thu Jun 17, 2004 7:13 pm
Yeah, i typed it wrong, sorry about that. That wasn't the cause of the problem though.
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Thu Jun 17, 2004 7:35 pm
I solved it. I guess PHP is doing it like it's supposed to be done
to change a static property I have to do it like this:
Code: Select all
<?
class editor {
static $pages = 'first';
function __construct () {
self::$pages = 'second'; // I have to edit this property on the class and not on the object
}
}
$test = new editor;
echo editor::$pages; // now it prints what it's supposed to: 'second'
?>