Jump to content

classes$function


fluteofliar

Recommended Posts

In php,AFAIK dollarsign($) is part of variable thatswhy we always variable

using this sign........

Now,whats wrong when i use the above defination while accessing a member variable of a class using object, for instance

<?php

class hello

{

public $a="php seems sometime illogical";

function _construct()

{

echo "howz your php experience?";

}

}

$obj=new hello();

$obj->a;//this works fine

$ob->$a;//error::can,t acess empty property?

 

2)does function are define at the point they call in php?

why its necessary to call inner function first before outer function in nested function

Link to comment
https://forums.phpfreaks.com/topic/206503-classesfunction/
Share on other sites

In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this:

 

$a = 'a';
$ob->$a;

 

When calling the property of a class you just don't use the dollar sign in front of the variable name, that's just how it is.

Link to comment
https://forums.phpfreaks.com/topic/206503-classesfunction/#findComment-1080174
Share on other sites

In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this:

$a has value but while accessing it like

obj->$a ... it means we are trying to acess the property of object which is refer as $$a inside the object

but the property $($a) is empty....well thankz mate for taking pain to reply my quest :)

Link to comment
https://forums.phpfreaks.com/topic/206503-classesfunction/#findComment-1080193
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.