Jump to content

Recommended Posts

Why can I override certain functions, but not others?

Example: (not the real code)
[code]<?php
Class myClass{
  var $str
 
  function extract(){
      return $this->str;
  }

  function print(){
    return $this->str;
  }
}
?>[/code]

It's fine with extract(), but when I add in the print() one, I get a parse error saying unexpected print. Why can I do this with extract but not print?
Link to comment
https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/
Share on other sites

You're mising a semi-colon after var $str

Extract() is a reserved function, while print() is reserved too but it's a language construct (can be used without parenthesis).

It's usually a bad idea to use variable or function names that are the same or similar to PHP reserved words.

hth.
Thx Hypnos. As I mentioned, it's a bad idea to use PHP resrved words for pretty much anything.

Same goes for MySQL - some people like to use a column name of password but it's reserved (you should use a different name or enclose it in backtick marks `password` within SQL and stored procedures).
Yeah every now and then I accidentally use a reserved MySQL word without knowing, and after a few minutes of trying to debug a query that looks fine, I always check the list.
I looked up functions, etc in the manual, but it didn't occur to me that print was a reserved PHP word. :D
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.