473,409 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

PHP OO Java Main Method equivalent???

Hey!

I'm new to OO in PHP but somewhat familiar with this paridigm in
JAVA....

So I was wondering if it is possible to have within a PHP script
something equivalent to a main method as it is possible in JAVA....

For example:

class myclass{
//my class's code
}

//Here is where I want to create a main method... or a function that
gets automatically called when the script is executed... that way this
"main" method would create instances of "myclass" and use them...
Cheers!

Jose

Jun 15 '07 #1
5 8707
On Jun 15, 6:57 am, pelon <pelonbiol...@gmail.comwrote:
Hey!

I'm new to OO in PHP but somewhat familiar with this paridigm in
JAVA....

So I was wondering if it is possible to have within a PHP script
something equivalent to a main method as it is possible in JAVA....

For example:

class myclass{
//my class's code

}

//Here is where I want to create a main method... or a function that
gets automatically called when the script is executed... that way this
"main" method would create instances of "myclass" and use them...

Cheers!

Jose

Have you tried a simple example?

Jun 15 '07 #2
fel
On Jun 15, 9:57 am, pelon <pelonbiol...@gmail.comwrote:
Hey!

I'm new to OO in PHP but somewhat familiar with this paridigm in
JAVA....

So I was wondering if it is possible to have within a PHP script
something equivalent to a main method as it is possible in JAVA....

<?php
class welcometophp {
function main(){
System.out.println("not that different from java, is it?");
}
}

welcometophp::main();
?>
>
For example:

class myclass{
//my class's code

}

//Here is where I want to create a main method... or a function that
gets automatically called when the script is executed... that way this
"main" method would create instances of "myclass" and use them...

Cheers!

Jose

Jun 15 '07 #3
On Jun 15, 9:57 am, pelon <pelonbiol...@gmail.comwrote:
Hey!

I'm new to OO in PHP but somewhat familiar with this paridigm in
JAVA....

So I was wondering if it is possible to have within a PHP script
something equivalent to a main method as it is possible in JAVA....

For example:

class myclass{
//my class's code

}

//Here is where I want to create a main method... or a function that
gets automatically called when the script is executed... that way this
"main" method would create instances of "myclass" and use them...
You can't get away without something outside, but you can do as the
person above me pointed out: make a static function and call it first
thing.
>
Cheers!

Jose

Jun 15 '07 #4
C.
On 15 Jun, 15:57, pelon <pelonbiol...@gmail.comwrote:
Hey!

I'm new to OO in PHP but somewhat familiar with this paridigm in
JAVA....

So I was wondering if it is possible to have within a PHP script
something equivalent to a main method as it is possible in JAVA....
First thing is the PHP, unlike Java has first class functions. Second
thing, is that PHP, like most scripting languages has an implicit
entry point at the beginning of the invoked file so all you need to do
is this:

BOF>>>>>>>>>>>
<?php

$obj = new myclass();

class myclass{
//my class's code
}

?>
<<<<<<<<<<<EOF

Although its generally considered neater to put class definitions in
their own include file so...

BOF>>>>>>>>>>>
<?php

require_once('myclass.inc.php');
$obj = new myclass();

?>
<<<<<<<<<<<EOF

HTH

C.

Jun 15 '07 #5
Have you read this?
http://www.php.net/manual/en/language.oop5.basic.php
pelon wrote:
Hey!

I'm new to OO in PHP but somewhat familiar with this paridigm in
JAVA....

So I was wondering if it is possible to have within a PHP script
something equivalent to a main method as it is possible in JAVA....

For example:

class myclass{
//my class's code
}

//Here is where I want to create a main method... or a function that
gets automatically called when the script is executed... that way this
"main" method would create instances of "myclass" and use them...
Cheers!

Jose
Jun 16 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Manfred Braun | last post by:
Hi All, I am able to invoke some methods from an instance of a loaded assembly, but I am not able to invoke the loaded assemblie's "Main" method. I try it this way: Assembly assembly =...
4
by: Sean Dockery | last post by:
I am a Java veteran who has just started learning C# with Tom Archer's Inside C# 2nd Ed. In the first chapter, there is a typical Hello, World! application that looks like this... namespace...
9
by: TechN00b | last post by:
I'm trying to write a quick commandline app that takes a string from the commandline and returns a formatted md5 hash. Unfortunately the code won't comple and returns an error of "No accessible...
8
by: garyusenet | last post by:
The following piece of code appears in an example i'm reading after the class has been named. public string userMessage; However if i move that into my main method, i'm told that the keyword...
19
by: shana07 | last post by:
Good Day All! I have one problem and wish to consult...... I am using one program -mujava to create mutants. I run the program and comes out this: MyProgram.java class containts 'static void...
1
by: jinnee | last post by:
I initialize some values in main() method. It seems the system doesn't call this method, because when I press F5 to debug, no line of this method is called. I don't know why it happens. Please...
6
by: unlikeablePorpoise | last post by:
I am trying to get JPype to pass a String into a Java class main function. Demonstration code below: =============JAVA============ package com; public class JPypeTest { public static void...
2
by: mahi543 | last post by:
how can we call one class main method from another class main method? i tried but i got an idea for method we can call one method from another method
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.