10 Replies - 1702 Views - Last Post: 02 March 2012 - 11:35 PM Rate Topic: -----

#1 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

how to override php echo

Posted 01 March 2012 - 09:50 PM

hi ,

i have a problem , I want two know how to overidde pho 'echo' .
instead echo I want to use a keyword like cout in c++.

plz help,

thx
menukadevinda
Is This A Good Question/Topic? 0
  • +

Replies To: how to override php echo

#2 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: how to override php echo

Posted 01 March 2012 - 10:27 PM

Why would you want to do this? Just curious.

But this code should do the trick


<?php

function cout($string) {
    
    print $string;
    
}

cout("This is a string");

?>




Though this code essentially still uses one of PHP's built in functions to write to the screen.
Was This Post Helpful? 0
  • +
  • -

#3 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: how to override php echo

Posted 01 March 2012 - 10:33 PM

no I think u have misunderstand me.

then, I have to always passe values to cout() methode.
like here print key word i want to create another word that do the same stuff.

thx for ur reply.
Was This Post Helpful? 0
  • +
  • -

#4 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: how to override php echo

Posted 01 March 2012 - 10:40 PM

I see I see. I don't think this is possible, but I'll look into it.

Seeing as echo is a language statement, and not a function, this isn't really possible.

Still, I'll look into something and see what I can find :)
Was This Post Helpful? 1
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: how to override php echo

Posted 01 March 2012 - 11:09 PM

View Postmenukadevinda, on 02 March 2012 - 05:50 AM, said:

instead echo I want to use a keyword like cout in c++.

why?
Was This Post Helpful? 1
  • +
  • -

#6 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: how to override php echo

Posted 01 March 2012 - 11:20 PM

I have an idea of writing my own framework in php. so keep it significant I want to use different syntax.
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: how to override php echo

Posted 01 March 2012 - 11:38 PM

*
POPULAR

so you intend to make your framework slow and ineffective to make it distinguishable?

besides that, (almost) every PHP coder knows how to use echo, cout would be new to learn. if you present cout why should I bother to use it when it doesn't have any advantage over echo?
Was This Post Helpful? 5
  • +
  • -

#8 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: how to override php echo

Posted 01 March 2012 - 11:46 PM

ok. I am agree with u, but do u know how to do this?
Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: how to override php echo

Posted 01 March 2012 - 11:48 PM

if you want to use cout like echo, I guess you would have to add it to the source code and compile it into your PHP executeable.
Was This Post Helpful? 0
  • +
  • -

#10 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: how to override php echo

Posted 02 March 2012 - 08:40 PM

This reminds me of when I used to define "newline" as "endl" just because I hated writing "endl".
Was This Post Helpful? 1
  • +
  • -

#11 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 39
  • View blog
  • Posts: 621
  • Joined: 15-December 09

Re: how to override php echo

Posted 02 March 2012 - 11:35 PM

Read up on this here:
http://www.php.net/m.../internals2.php

You can probably create an alias for echo or print.

Seems like a lot of extra work, but hey what do I know. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1