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!
I'd like to create a class and echo it, that's it!
What I would like to do is create an 'error' class that I can use in my templating system to enable or disable error messages. I'd like to be able to simply echo the class. What code can I strip from this and still have the page echo '1' as the value?
<?php
class error {
private $query;
public function set($name,$value) {$this->$name = $value;}
public function get($name){return $this->$name;}
}
$error = new error();
$error->set('query',"1");
echo $error->get('query');
?>
JAB Creations wrote:I'd like to create a class and echo it, that's it!
What I would like to do is create an 'error' class that I can use in my templating system to enable or disable error messages. I'd like to be able to simply echo the class. What code can I strip from this and still have the page echo '1' as the value?
<?php
class error {
private $query;
public function set($name,$value) {$this->$name = $value;}
public function get($name){return $this->$name;}
}
$error = new error();
$error->set('query',"1");
echo $error->get('query');
?>
The thread to figure out what the minimal amount of code I need to be able to declare a class on one page and so that I could echo it's value on another.
The last post I made without comment was that that code worked though I'm not sure if it's yet minimal...which I should have clarified.
Classes exist to be used as universal variables, sort of like a super global but without the security concerns.
I'd want to declare a class and a value so that I could determine if the class exists in a different file.
I want to echo the class's value to ensure that it has actually been set.
If I can't echo the class on a second file I am less if at all likely to know if the desired behavior exists by accident or if it's working as desired because it's correctly written.
The return is within the class declaration and therefor is less then minimal code to echo the class's value on a second file.