Jump to content

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!  :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.