Originally posted by GumSlone
View Post
How to work with a class in PHP?
Collapse
X
-
PHP Code:<?php class testClass { var $test1; public function __construct($test2) { $this->test2 = $test2; $this->test6 = 6; } public function show($test3) { global $test4, $test5; return $this->test1.$this->test2.$test3.$test4.$test5.$this->test6; } } $testClass = new testClass(2); $testClass->test1 = 1; $test4 = 4; $test5 = 5; echo $testClass->show(3); ?>
- Likes 1
Leave a comment:
-
How to work with a class in PHP?
I am back at php after a motorbike accident, and I have lost most of my memory, but not my love for web.
Now I am just learning/exercising again, and I am facing first problems I can't handle/solve!
In the php code I am writing, here is the situation:
* there are six variables to deal with: $test1, $test2, $test3, $test4, $test5, $test6
* 3 is passing through the function show() as a parameter (OK)
* 4 is being called from within the function show() as a global (OK)
* 1, 2, 5, 6 are not being shown. why?
Thanks in advance!
PHP Code:<?php class testClass { var $test1; public function __construct($test2) { $test2 = $test2; $test6 = 6; } public function show($test3) { global $test4; return $test1.$test2.$test3.$test4.$test5.$test6; } } $testClass = new testClass(2); $testClass->test1 = 1; $test4 = 4; $test5 = 5; echo $testClass->show(3); ?>
Leave a comment: