hi all,
im a first time php programmer however long time C# / javascript / vb.net / etc programmer so i am fully versed in oop and know how to program (theory, etc).
I am charged with making a rather simple search class in php that uses XPath. I just have some basic questions about classes in php before i get too far along.
1. Are classes in php similar to C# where i can have the class in a separate physical file and include it in another php file, then instantiate it and call its methods just like :
include myclass.php
FTSearch mySearch = new FTSearch() // construct it
var $myArray = mySearch.PerformSearch(blah) //activate a method that returns a string or array
2. also how do i construct a method that returns a value? in C# it would be like :
public string ThisReturnsAString(){
return myString;
}
thats it for now.
thanks in advance,
mcm
classes - beginner question
Moderator: General Moderators
Re: classes - beginner question
in php return statement inside the function is used to return a value.return statement causes the function to end its execution immediately and pass control back to the line from which it was called. here modifier public and return datatype string is not usedalso how do i construct a method that returns a value? in C# it would be like :
public string ThisReturnsAString(){
return myString;
}
Code: Select all
function ThisReturnsAString()
{
return $myString;
}
Re: classes - beginner question
They are used in PHP5 Classes, which I believe the OP was asking.webspider wrote:here modifier public and return datatype string is not used
Code: Select all
<?php
class Test_Class{
private $Val = null;
public $Val2 = null;
public function getVal(){
return $this->Val;
}
public function setVal($Value){
$this->Val = $Value;
return true;
}
// Static
static public function _getVal(){
return self::$Val;
}
static public function _setVal($Value){
self::$Val = $Value;
return true;
}
}
Re: classes - beginner question
Almost:mcmcom wrote: include myclass.php
FTSearch mySearch = new FTSearch() // construct it
var $myArray = mySearch.PerformSearch(blah) //activate a method that returns a string or array
Code: Select all
include 'myclass.php';
$mySearch = new FTSearch();
$myArray = $mySearch->PerformSearch('blah');Real programmers don't comment their code. If it was hard to write, it should be hard to understand.