areric Posted April 11, 2006 Share Posted April 11, 2006 Ok all im having a few problems and for the life of me cant figure this out. Im trying some object oriented php for the first time. Specifically a image manipulation library. At the same time im trying to write it in a test driven fashion. Im calling the function in my class from a function in my test class and getting an error. The weird thing is i have a third class for test utilities and i use that the SAME way and it works. THat said heres the code:ImageModifierTest.php[code]<? include("TestLib.php"); ?><? include("ImageModifier.php"); ?><? class ImageModifierTest //implements ITest { var $imageModifier; function __construct() { } function TestOpenBinaryStream() { $streamToSend = "111010001010001"; $this->$imageModifier = new ImageModifier(); $this->$testHelpers = new TestHelpers(); return $this->$imageModifier->OpenBinaryStream($streamToSend); //return $this->$testHelpers->AssertAreEqual($binaryStream, $streamToSend); } function ExecuteTests() { $success = $this->TestOpenBinaryStream(); if ($success == true) { return "Success"; } else { return "Failure"; } } }?><? $imageModifierTests = new ImageModifierTest(); echo $imageModifierTests->ExecuteTests();?>[/code]ImageModifier.php[code]<? //include("ITest.php"); ?><? class ImageModifier { //MEMBERS var $mImage = ""; var $mModifiedImage = ""; var $mBinaryImageStream = ""; function __construct() { } function SetImageFile($image) { $mImage = $image; } function OpenBinaryStream($stream) { $this->$mImage = $stream; $this->$mBinaryImageStream = $stream; return $this->$mImage; } }?>[/code]TestLib.php[code]<? //TEST Helpersclass TestHelpers{ function AssertAreEqual($lhs, $rhs) { return $lhs == $rhs; }}?>[/code]You might notice i have some commented out code in there. I was going to write this with interfaces and a few other features but then found out they are php5 only and im using php4 on my server. The error message i get is : [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Fatal error: Call to undefined function: openbinarystream() in /home/flyerweb/public_html/imagelibrary/ImageModifierTest.php on line 16[/quote][b]Any ideas?[/b]ThanksNote: Seeing how i commented out the AssertEquals above i should let you all know when that is uncommented it works fine. But the one above it doesnt. Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted April 11, 2006 Share Posted April 11, 2006 When your pointing to variables in your class, you shouldn't be including the $ (only for $this->x), since your not initializing the classes with any values, we don't need to call them as "functions". You can also save resources, by creating a reference to the class.WRONG:[code]$this->$imageModifier = new ImageModifier();$this->$testHelpers = new TestHelpers();[/code]RIGHT:[code]$this->imageModifier = & new ImageModifier;$this->testHelpers = & new TestHelpers;[/code]Fix up the rest of your code and give it a try :) Quote Link to comment Share on other sites More sharing options...
areric Posted April 11, 2006 Author Share Posted April 11, 2006 [!--quoteo(post=363513:date=Apr 10 2006, 08:33 PM:name=heckenschutze)--][div class=\'quotetop\']QUOTE(heckenschutze @ Apr 10 2006, 08:33 PM) [snapback]363513[/snapback][/div][div class=\'quotemain\'][!--quotec--]When your pointing to variables in your class, you shouldn't be including the $ (only for $this->x), since your not initializing the classes with any values, we don't need to call them as "functions". You can also save resources, by creating a reference to the class.WRONG:[code]$this->$imageModifier = new ImageModifier();$this->$testHelpers = new TestHelpers();[/code]RIGHT:[code]$this->imageModifier = & new ImageModifier;$this->testHelpers = & new TestHelpers;[/code]Fix up the rest of your code and give it a try :)[/quote]Awesome thanks heckenschutze, you actually answered two questions for the price of one :) I was trying to figure out how to do references. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.