sorenchr Posted June 16, 2008 Share Posted June 16, 2008 Hi there, i'm new to OOP in PHP, so i tried to create a simple script of my own, however this doesn't work. Can anybody tell me why? // Setup varStrip class class varStrip { var $targetstrip; function numOnly($this->targetstrip) { if(preg_match("/^[0-9]+$/",$this->targetstrip)) { return true; echo "true"; } else { return false; echo "false"; } } } $varStrip = new varStrip(); $varStrip->numOnly(10); Link to comment https://forums.phpfreaks.com/topic/110394-why-doesnt-my-oop-script-work/ Share on other sites More sharing options...
vbnullchar Posted June 16, 2008 Share Posted June 16, 2008 <?php class varStrip { function numOnly($targetstrip) { if(preg_match("/^[0-9]+$/",$targetstrip)) { return true; //echo "true"; } else { return false; //echo "false"; } } } $varStrip = new varStrip(); echo $varStrip->numOnly(10); ?> Link to comment https://forums.phpfreaks.com/topic/110394-why-doesnt-my-oop-script-work/#findComment-566352 Share on other sites More sharing options...
sorenchr Posted June 16, 2008 Author Share Posted June 16, 2008 Thanks! What if i want to keep the class in a seperate file, and then load it in to my php document when i need it? Link to comment https://forums.phpfreaks.com/topic/110394-why-doesnt-my-oop-script-work/#findComment-566361 Share on other sites More sharing options...
vbnullchar Posted June 16, 2008 Share Posted June 16, 2008 require('YOUR_PHP_FILE'); Link to comment https://forums.phpfreaks.com/topic/110394-why-doesnt-my-oop-script-work/#findComment-566363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.