Jump to content

Why doesn't my OOP script work?


sorenchr

Recommended Posts

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

<?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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.