473,382 Members | 1,563 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,382 software developers and data experts.

Is there a generic Object in PHP?

Hi,

I would like to have a function that takes a generic object and takes
some action on this. Something like,

function AMethod(Object obj) {
DoSomeStufftotheObject;
}

then be able to pass various object types in. Is there a way to do
this in PHP? Do classes automatically inherit from a generic Object
like in Java?

Thanks.
Jan 16 '08 #1
5 8263
KDawg44 wrote:
Hi,

I would like to have a function that takes a generic object and takes
some action on this. Something like,

function AMethod(Object obj) {
DoSomeStufftotheObject;
}

then be able to pass various object types in. Is there a way to do
this in PHP? Do classes automatically inherit from a generic Object
like in Java?

Thanks.
No, there is no generic object in PHP. However, you don't need to
specify what kind of object is being passed, i.e.

function AMethod($obj) {

will take anything (not just objects). And from there you can figure
out what was passed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jan 16 '08 #2
On Jan 15, 9:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
KDawg44 wrote:
Hi,
I would like to have a function that takes a generic object and takes
some action on this. Something like,
function AMethod(Object obj) {
DoSomeStufftotheObject;
}
then be able to pass various object types in. Is there a way to do
this in PHP? Do classes automatically inherit from a generic Object
like in Java?
Thanks.

No, there is no generic object in PHP. However, you don't need to
specify what kind of object is being passed, i.e.

function AMethod($obj) {

will take anything (not just objects). And from there you can figure
out what was passed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Thank you.... my brain is stuck in JAVA mode and i forgot you do not
have to declare what is being passed in!

Thanks!
Jan 16 '08 #3
KDawg44 wrote:
On Jan 15, 9:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>KDawg44 wrote:
>>Hi,
I would like to have a function that takes a generic object and takes
some action on this. Something like,
function AMethod(Object obj) {
DoSomeStufftotheObject;
}
then be able to pass various object types in. Is there a way to do
this in PHP? Do classes automatically inherit from a generic Object
like in Java?
Thanks.
No, there is no generic object in PHP. However, you don't need to
specify what kind of object is being passed, i.e.

function AMethod($obj) {

will take anything (not just objects). And from there you can figure
out what was passed.

Thank you.... my brain is stuck in JAVA mode and i forgot you do not
have to declare what is being passed in!

Thanks!
:-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jan 16 '08 #4
KDawg44 wrote:
On Jan 15, 9:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>KDawg44 wrote:
>>Hi,
I would like to have a function that takes a generic object and takes
some action on this. Something like,
function AMethod(Object obj) {
DoSomeStufftotheObject;
}
then be able to pass various object types in. Is there a way to do
this in PHP? Do classes automatically inherit from a generic Object
like in Java?
Thanks.
No, there is no generic object in PHP. However, you don't need to
specify what kind of object is being passed, i.e.

function AMethod($obj) {

will take anything (not just objects). And from there you can figure
out what was passed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thank you.... my brain is stuck in JAVA mode and i forgot you do not
have to declare what is being passed in!

Thanks!
you can also do if(is_object($var)) to make sure its an object.

--
Daniel Ennis
faNetworks.net - Quality Web Hosting and Ventrilo Services
System Administrator / Web Developer
PHP Developer for 6 years
da****@fanetworks.net
Jan 16 '08 #5
try using this a generic object:

$obj = new stdClass();

On Jan 15, 6:14*pm, KDawg44 <KDaw...@gmail.comwrote:
Hi,

I would like to have a function that takes a generic object and takes
some action on this. * Something like,

function AMethod(Object obj) {
* * * * *DoSomeStufftotheObject;

}

then be able to pass various object types in. *Is there a way to do
this in PHP? *Do classes automatically inherit from a generic Object
like in Java?

Thanks.
Jan 16 '08 #6

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

Similar topics

6
by: Steven Bethard | last post by:
So I thought I'd try to summarize a few things here and maybe we can move toward filing a PEP. I'm not really sure I'm the right person to champion it because, as I've mentioned, I usually...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
4
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
10
by: phancey | last post by:
I'm quite new to generics. I have 2 generic classes: MyClass<Tand MyOtherClass<T>. MyClass<Thas 2 public Add methods Add(MyOtherClass<T>); Add(MyOtherClass<Wrapper<T>>); (Wrapper<Tis another...
10
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a...
2
by: ADN | last post by:
Hi, I have a method which calls my service factory: class person { public int ID { get; set: } public string Name {get; set;} } IList<Personmypeople = __serviceFactory.Fetch(new Person())
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.