By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

call to undefined function php5

P: n/a
I'm writing a class to handle reading/writing from/to files like this
(shortened)

lass FileIO{
private $filename;
private $mode;
private $filePointer;
private $dictionary;

public function __construct($filename = null, $mode = 'r+'){
$this->filename = $filename;
$this->mode = $mode;
$this->filePointer = $this->openFile();
$this->dictionary = array();
}

public function openFile(){
return fopen($this->filename, $this->mode);
}

public function writeURL($name, $url){
$content = $name . " $ " . $url. "\n";
$this->fwrite($this->filePointer, $content);
}

when I try to call my writeURL(string, string) method the parser
returns an error of "call to undefined function)
my call:

include_once('FileIO.php');
$myFileIO = new FileIO('siv.txt');
$myFileIO.writeURL("siv", "nibbler.no");

this is copy/paste, so there's no typing error in the methodcall
(writeURL())
What am I doing wrong?

Feb 28 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
kay
very very fast guess... and probably not helfpul

lass FileIO{
private $filename;
its lass not class.... ?

Feb 28 '06 #2

P: n/a
not that easy, wrong during copy..
it says class FileIO{

//code
}

When I run a var_dump on this line in the __construct
$this->filePointer = $this->openFile();

it returns false...
I guess it should return true if the file really is opened?

Feb 28 '06 #3

P: n/a
Ksu
class FileIO{
private $filename;
private $mode;
private $filePointer;
private $dictionary;

public function __construct($filename = null, $mode = 'w+'){
//not r!!! r - is read w - is write w+ - can create file
$this->filename = $filename;
$this->mode = $mode;
$this->filePointer = $this->openFile();
$this->dictionary = array();
}

public function openFile(){
return fopen($this->filename, $this->mode);
}

public function Write(){
return fwrite($this->filePointer,$content);
}
//create new function for writing or use standart - but use it
RIGHT!!!!
public function writeURL($name, $url){
$content = $name . " $ " . $url. "\n";
$this->Write($content);
}
}

$myFileIO = new FileIO('siv.txt');
$myFileIO->writeURL("siv", "nibbler.no");

Feb 28 '06 #4

P: n/a
Cruella DeVille wrote:
I'm writing a class to handle reading/writing from/to files like this
(shortened)

lass FileIO{
private $filename;
private $mode;
private $filePointer;
private $dictionary;

public function __construct($filename = null, $mode = 'r+'){
$this->filename = $filename;
$this->mode = $mode;
$this->filePointer = $this->openFile();
$this->dictionary = array();
}

public function openFile(){
return fopen($this->filename, $this->mode);
}

public function writeURL($name, $url){
$content = $name . " $ " . $url. "\n";
$this->fwrite($this->filePointer, $content);
}

when I try to call my writeURL(string, string) method the parser
returns an error of "call to undefined function)
my call:

include_once('FileIO.php');
$myFileIO = new FileIO('siv.txt');
$myFileIO.writeURL("siv", "nibbler.no");

this is copy/paste, so there's no typing error in the methodcall
(writeURL())
What am I doing wrong?


Which line is giving you the undefined function?

Also, when you open the file you need to open it as "w" to truncate and
write to it, or "a" to append to it ("w+" or "a+" to read and write).
"r+" only opens it for reading.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 28 '06 #5

P: n/a
On 28 Feb 2006 13:31:52 -0800, "Cruella DeVille" <si********@gmail.com> wrote:
include_once('FileIO.php');
$myFileIO = new FileIO('siv.txt');
$myFileIO.writeURL("siv", "nibbler.no");


"." is the string concatenation operator.

You want "->", which can be used to call object methods (and dereference
object variables).

WHat you've written tries to string concatenate $myFileIO with the results of
a call to the global-scope function "writeURL" - which doesn't exist - and then
it ignores the actual result as it's not assigned to anything.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Feb 28 '06 #6

P: n/a
I still get the same error,
Fatal error: Call to undefined function writeUrl() in
C:\wamp\www\bookmarks\Classes\testFileIO.php on line 6

my function:
public function writeUrl($name, $url){
$content = $name . " $ " . $url. "\n";
fwrite($this->filePointer, $content);
}

my call:
include_once('FileIO.php');
$myFileIO = new FileIO('siv.txt', 'w+');
//$myFileIO.readFile($this);
$myFileIO.writeUrl("siv", "nibbler.no"); <- this is line 6

And I can't understand why...

Feb 28 '06 #7

P: n/a
IIIIk, so embarrassing!! Been doing alot of Java lately

Sorry for bothering you all!

Feb 28 '06 #8

P: n/a
Cruella DeVille wrote:
I'm writing a class to handle reading/writing from/to files like this
(shortened)

lass FileIO{
private $filename;
private $mode;
private $filePointer;
private $dictionary;

public function __construct($filename = null, $mode = 'r+'){
$this->filename = $filename;
$this->mode = $mode;
$this->filePointer = $this->openFile();
$this->dictionary = array();
}

public function openFile(){
return fopen($this->filename, $this->mode);
}

public function writeURL($name, $url){
$content = $name . " $ " . $url. "\n";
$this->fwrite($this->filePointer, $content);
}

when I try to call my writeURL(string, string) method the parser
returns an error of "call to undefined function)
my call:

include_once('FileIO.php');
$myFileIO = new FileIO('siv.txt');
$myFileIO.writeURL("siv", "nibbler.no");

this is copy/paste, so there's no typing error in the methodcall
(writeURL())
What am I doing wrong?

You are using Java semantics...

$myFileIO->writeURL('siv', 'nibbler.no');

-david-

Mar 1 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.