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

new Object()->function() ?

Mtr
this results in "unexpected T_OBJECT_OPERATOR" Parse error

How do I do this, without needing two lines such as

$o = new Object();
$o->function();

Also, what does "unexpected T_OBJECT_OPERATOR" mean?
Oct 1 '07 #1
11 3256
(new Object())->function()

Mtr wrote:
this results in "unexpected T_OBJECT_OPERATOR" Parse error

How do I do this, without needing two lines such as

$o = new Object();
$o->function();

Also, what does "unexpected T_OBJECT_OPERATOR" mean?
It means that the -is unexpected at that point.
Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Oct 1 '07 #2
On Oct 1, 9:37 am, Mtr <M...@no.spamwrote:
this results in "unexpected T_OBJECT_OPERATOR" Parse error

How do I do this, without needing two lines such as

$o = new Object();
$o->function();

Also, what does "unexpected T_OBJECT_OPERATOR" mean?
You don't. That syntax (new Object()->function()) isn't supported.
That's why you get "unexpected T_OBJECT_OPERATOR."

Oct 1 '07 #3
Mtr
On Mon, 01 Oct 2007 15:41:35 +0200, Willem Bogaerts
<w.********@kratz.maardanzonderditstuk.nlwrote:
>(new Object())->function()

Mtr wrote:
>this results in "unexpected T_OBJECT_OPERATOR" Parse error

How do I do this, without needing two lines such as

$o = new Object();
$o->function();

Also, what does "unexpected T_OBJECT_OPERATOR" mean?

It means that the -is unexpected at that point.
Yes, thanks, but more precisely: the "->" is not an operator, nor is it
text. (I assume that "T" is short for text.) So it's unclear what this
error msg means.

Let me refine my example, so as not to use any reserved word like
"function"

$o = new MyObject()->myFunction() does not work:

If I know what the error means, it will be easier to remember.

Oct 1 '07 #4
On Oct 1, 9:49 am, Mtr <M...@no.spamwrote:
>
Yes, thanks, but more precisely: the "->" is not an operator, nor is it
text. (I assume that "T" is short for text.) So it's unclear what this
error msg means.
The T is short for "token."

Oct 1 '07 #5
..oO(Mtr)
>On Mon, 01 Oct 2007 15:41:35 +0200, Willem Bogaerts
<w.********@kratz.maardanzonderditstuk.nlwrote:
>>Also, what does "unexpected T_OBJECT_OPERATOR" mean?

It means that the -is unexpected at that point.

Yes, thanks, but more precisely: the "->" is not an operator
It is an operator, like "::".
>nor is it
text. (I assume that "T" is short for text.)
The "T" means token.
>So it's unclear what this
error msg means.
The parser simply doesn't expect a "->" token at that point.
>Let me refine my example, so as not to use any reserved word like
"function"

$o = new MyObject()->myFunction() does not work:

If I know what the error means, it will be easier to remember.
The message is pretty clear. PHP doesn't support this syntax.

Micha
Oct 1 '07 #6
Mtr
On Mon, 01 Oct 2007 15:58:36 +0200, Michael Fesser <ne*****@gmx.dewrote:
>.oO(Mtr)
>>On Mon, 01 Oct 2007 15:41:35 +0200, Willem Bogaerts
<w.********@kratz.maardanzonderditstuk.nlwrote :
>>
Yes, thanks, but more precisely: the "->" is not an operator

It is an operator, like "::".
oh really? then perhaps you can tell us what "operation" is being performed
Oct 2 '07 #7
..oO(Mtr)
>On Mon, 01 Oct 2007 15:58:36 +0200, Michael Fesser <ne*****@gmx.dewrote:
>>>On Mon, 01 Oct 2007 15:41:35 +0200, Willem Bogaerts
<w.********@kratz.maardanzonderditstuk.nlwrot e:
>>>Yes, thanks, but more precisely: the "->" is not an operator

It is an operator, like "::".

oh really? then perhaps you can tell us what "operation" is being performed
The object is dereferenced. From the manual:

| An operator is something that you feed with one or more values (or
| expressions, in programming jargon) which yields another value (so
| that the construction itself becomes an expression).

Micha
Oct 2 '07 #8
Mtr
On Tue, 02 Oct 2007 17:07:10 +0200, Michael Fesser <ne*****@gmx.dewrote:
>The object is dereferenced. From the manual:

| An operator is something that you feed with one or more values (or
| expressions, in programming jargon) which yields another value (so
| that the construction itself becomes an expression).
quoting the manual can only try to indicate what the authors of PHP say.
That is not any proof that it really is an operator. If they say that the
sun is blue, would you believe that, too?

The fact is that no operation is being performed, and so "->" is not an
operator in the conventioned use of the term.

In another language, Object.property would not indicate that the dot is an
operator of any kind. The author(s) of PHP shot themselves in the foot
early on when they decided to use the the dot for string concatenation
rather than the same plus sign that nearly everybody else uses. So now they
have to use the clunky '->' where they should be using a dot. It still just
denotes that a method or variable belongs to the object.
Oct 2 '07 #9
Mtr
On Tue, 02 Oct 2007 17:07:10 +0200, Michael Fesser <ne*****@gmx.dewrote:
>The object is dereferenced. From the manual:

| An operator is something that you feed with one or more values (or
| expressions, in programming jargon) which yields another value (so
| that the construction itself becomes an expression).

for instance, from the manual on Classes and Objects:

"To create an instance of a class, a new object must be created and
assigned to a variable."

That is just not true. The fact that it is in the manual doesn't make it
more true.
Oct 2 '07 #10
Mtr wrote:
On Tue, 02 Oct 2007 17:07:10 +0200, Michael Fesser <ne*****@gmx.dewrote:
>The object is dereferenced. From the manual:

| An operator is something that you feed with one or more values (or
| expressions, in programming jargon) which yields another value (so
| that the construction itself becomes an expression).

quoting the manual can only try to indicate what the authors of PHP say.
That is not any proof that it really is an operator. If they say that the
sun is blue, would you believe that, too?

The fact is that no operation is being performed, and so "->" is not an
operator in the conventioned use of the term.
But there IS an operation being performed. You are dereferencing the
object. And it has precedence (pretty high) and associativity (left to
right).
In another language, Object.property would not indicate that the dot is an
operator of any kind. The author(s) of PHP shot themselves in the foot
early on when they decided to use the the dot for string concatenation
rather than the same plus sign that nearly everybody else uses. So now they
have to use the clunky '->' where they should be using a dot. It still just
denotes that a method or variable belongs to the object.
And in another language (specifically C++ or Java), the dot is an
operator.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 2 '07 #11

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:wL******************************@comcast.com. ..
Mtr wrote:
>On Tue, 02 Oct 2007 17:07:10 +0200, Michael Fesser <ne*****@gmx.de>
wrote:
>>The object is dereferenced. From the manual:

| An operator is something that you feed with one or more values (or
| expressions, in programming jargon) which yields another value (so
| that the construction itself becomes an expression).

quoting the manual can only try to indicate what the authors of PHP say.
That is not any proof that it really is an operator. If they say that the
sun is blue, would you believe that, too?

The fact is that no operation is being performed, and so "->" is not an
operator in the conventioned use of the term.

But there IS an operation being performed. You are dereferencing the
object. And it has precedence (pretty high) and associativity (left to
right).
>In another language, Object.property would not indicate that the dot is
an
operator of any kind. The author(s) of PHP shot themselves in the foot
early on when they decided to use the the dot for string concatenation
rather than the same plus sign that nearly everybody else uses. So now
they
have to use the clunky '->' where they should be using a dot. It still
just
denotes that a method or variable belongs to the object.

And in another language (specifically C++ or Java), the dot is an
operator.
lol. i was going to ask him what term he gave a 'dot'...seems like 'denotes
that a method or variable belongs to the object' is a bit looong AND obtuse.
;^)
Oct 2 '07 #12

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

Similar topics

0
by: Gijs Korremans | last post by:
Hi, One of the functions in the com object I need to use has a pointer in one of it's functions (object.function(string input, struct * output)) (I've created the struct with...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
0
by: Chumley the Walrus | last post by:
I have a datalist, and I need to display the appropriate weekday contigent upon the date that exists in my 'showdate' record (which is a datetime datatype): <% if...
8
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { }...
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
3
by: aroldao | last post by:
Greetings Everyone, In php it's possible to create a new object based on a name stored in variable, i.e: $className = "CSome$name"; $newclass = new $className(); However is it possible to...
0
by: Jagdish | last post by:
Hello, Every body I have recently joined this group and I want to know how to pass Array of string to a Com object function.. Actually I want to pass String array from VB6 to Com Interface...
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
1
by: Pmarashian | last post by:
I am trying to get this code to work. I have bolded the line of code in question. function InsertFlashObj(name, table, td, element, maxH, code) { this.obj_name = name;...
1
by: Aron | last post by:
Hello the forum, I had a question about the function Douglas Crockford provided to remove the "new" operator from everyday coding syntax: function object (o) { function F() {} ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.