Jump to content

php class - having trouble with structuring


ultrus

Recommended Posts

Hello,

I'm a bit new on using classes in php, but not for long! I'm running into error messages when using the following code:

 

class Sapi {
var $voiceObj;

function Sapi($voiceObj) {
	$this->$voiceObj = new COM("SAPI.SpVoice");
}

function speak($text) {
	$this->$voiceObj->Speak($text);
}
}

$tts = new Sapi();

 

Error message: "Warning: Missing argument 1 for sapi() in /home/content/u/l/t/ultrus/html/sapi.php on line 11"

 

The following simplified example brings the same error message:

 

class Sapi {
var $voiceObj;

function Sapi($voiceObj) {
	$this->$voiceObj = "hello";
}
}

$tts = new Sapi();

 

Any idea on how to fix this? I think I'm close. Thanks in advance :)

Incidently, PHP has a neat feature that allows optional arguments with a default value.

 

<?php

function test($arg1 = '') {return strtolower($arg1);}

test();

?>

 

I should have mentioned that earlier, but your example didn't really need an argument.  Good luck with OOP!  :)

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.