Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Accessing variable


Go to End


736 Views

Avatar
jkdude

Community Member, 19 Posts

26 March 2016 at 2:38pm

Edited: 26/03/2016 2:46pm

Hi,

I've created a class and I can't seem to access its variables.

Encrypt.php

<?php
class Encrypt extends dataobject {
    private $key = "key1";
    public function DoEncrypt($code){
        $key = "key2";
        return $key . " | " . $this->key . " |";
    }
}

Page.php

public function Code(){
	return Encrypt::DoEncrypt("45");
}

Result

key2 | |

How do I access $key outside the function.

Thanks in advance.