For some reason when I print_r a variable containing an object I get data. However when I try to access each item using the -> notation it says it is NULL.
Here is the print_r dump of $user_data:
STDCLASS OBJECT (
[UACC_ID] => 6
[UACC_GROUP_FK] => 1
[UACC_EMAIL] => xxx#GMAIL.COM
[UACC_USERNAME] => xxxx
[UACC_PASSWORD] => $2A$08$CLSxxxxxxEOS7D2NDCSDD3P6A6
[UACC_IP_ADDRESS] => xx.xxx.xx.65
[UACC_SALT] => C64JYWY7ZS
[UACC_ACTIVATION_TOKEN] =>
[UACC_FORGOTTEN_PASSWORD_TOKEN] =>
[UACC_FORGOTTEN_PASSWORD_EXPIRE] => 0000-00-00 00:00:00
[UACC_UPDATE_EMAIL_TOKEN] =>
[UACC_UPDATE_EMAIL] =>
[UACC_ACTIVE] => 1
[UACC_SUSPEND] => 0
[UACC_FAIL_LOGIN_ATTEMPTS] => 0
[UACC_FAIL_LOGIN_IP_ADDRESS] =>
[UACC_DATE_FAIL_LOGIN_BAN] => 0000-00-00 00:00:00
[UACC_DATE_LAST_LOGIN] => 2013-05-05 07:18:34
[UACC_DATE_ADDED] => 2013-04-28 09:34:39
[UGRP_ID] => 1
[UGRP_NAME] => PUBLIC
[UGRP_DESC] => PUBLIC USER : HAS NO ADMIN ACCESS RIGHTS.
[UGRP_ADMIN] => 0
[UPRO_ID] => 6
[UPRO_UACC_FK] => 6
[UPRO_COMPANY] =>
[UPRO_FIRST_NAME] => xxxx
[UPRO_LAST_NAME] => xxxxx
[UPRO_PHONE] => 01392
[UPRO_NEWSLETTER] => 0
[UADD_ID] =>
[UADD_UACC_FK] =>
[UADD_ALIAS] =>
[UADD_RECIPIENT] =>
[UADD_PHONE] =>
[UADD_COMPANY] =>
[UADD_ADDRESS_01] =>
[UADD_ADDRESS_02] =>
[UADD_CITY] =>
[UADD_COUNTY] =>
[UADD_POST_CODE] =>
[UADD_COUNTRY] =>
)
However, when I try this I get NULL:
var_dump($user_data->UACC_ID);
I can't seem to echo anything by using the notation $user_data->UACC_EMAIL etc. What am I doing wrong?
Thank you all. It appears the output was being converted to ALLCAPS in CSS and so I didn't realise that the library actually uses the lower case variants.
Thanks.
One possibilities, however strange, is that the object has a __get function defined to capture and return null on internal private data points, to prevent php from throwing fatal "cant access private" errors if you try accessing any data directly.
so, yes, UACC_ID exists, and is in there, but is being intercepted.
Related
I am having an associative array like this:
[1] => Array
(
[logo] =>
[starting] =>
[prelim_info] =>
[state_entry] => 1
[district_entry] => 3
[CLIx_code] => 1009
[survey_time] => 2017-05-29 09:38:00.0
[Implement_module] =>
[CLIxModule_Impl] => 1
[Noimplement_reason] =>
[Other_Reason] =>
[implementedModule_Name] => 7 10 11 12
[Lab_Open] => 3
[Lab_Management] => 1
[Planned_CLIxPeriods] => 2
[ReasonsCancellation_CLIxClass] => 5
[PowerCut_Visit] => 2
[Observe_session:Session_observe] => 2
[Observe_session:grade_observe] =>
[Observe_session:grade_other] =>
[Observe_session:Module_Observed] =>
[Observe_session:Unit_Observed] =>
[Observe_session:Lesson_Observed] =>
[Observe_session:time_Sufficient] =>
[Observe_session:Student_workindependent] =>
[Observe_session:groupsinteracting] =>
[Observe_session:groupshelping] =>
[Observe_session:Students_Mothertongue] =>
[Observe_session:Students_handbook] =>
[Observe_session:Students_reflections] =>
[Observe_session:teacherpresent] =>
[Observe_session:encourage_platform] =>
[Observe_session:encourage_classdisc] =>
[Observe_session:mothertongue_teacher] =>
[Observe_session:teacher_handbook] =>
[Observe_session:Teacher_prepared] =>
[TPDcertification_support1:TPD_Cert_Subject1] =>
[TPDcertification_support1:tchrSupport_TPD1] =>
[TPDcertification_support1:Source_Support] =>
[TPDcertification_support2:TPD_Cert_Subject2] =>
[TPDcertification_support2:tchrSupport_TPD2] =>
[TPDcertification_support2:Source_Support] =>
[TPDcertification_support3:TPD_Cert_Subject] =>
[TPDcertification_support3:tchrSupport_TPD3] =>
[TPDcertification_support3:Source_Support] =>
[TPDcertification_support4:TPD_Cert_Subject] =>
[TPDcertification_support4:tchrSupport_TPD4] =>
[TPDcertification_support4:Source_Support] =>
[teacher_feedback] => Regarding the old modules, maths teachers said that it was very useful as well as workbook.
[FSP_feedback] => NA
[TPDsuppport_certification:Supt_TPDcertification] => 1
[TPDsuppport_certification:Source_Supportcertification] => 4
[teacherSupport_moduleImplement] => They had training organised by the clix team and RMSA.
[HighPoint] => NA
[LowPoint] => There was no clix class since school reopen.
[schlcontact_FSP_nooftimes] => 0
[FT_contactreason] => 5
[FT_otherreason] =>
[Support_fromTE] => 2
[Action_FT] => 1
[Specific_ActionFT] => School lab need to recheck for start rolling out the modules.
[Action_CLIxTeam] => 2
[Sepecific_ActionCLIx] =>
[Action_State] => 1
[Specific_ActionState] => To issue the class period include in their regular time table.
[Action_TPD] => 2
[Specific_ActionTPD] =>
[Session_observe2:Module_Second] =>
[Session_observe2:Observe_grade] =>
[Session_observe2:other_grade] =>
[Session_observe2:Observation_Module2] =>
[Session_observe2:Observation_Unit2] =>
[Session_observe2:Observation_Lesson2] =>
[Session_observe2:time_Sufficient2] =>
[Session_observe2:Student_workindependent2] =>
[Session_observe2:groupsinteracting2] =>
[Session_observe2:groupshelping2] =>
[Session_observe2:Students_Mothertongue2] =>
[Session_observe2:Students_handbook2] =>
[Session_observe2:Students_reflections2] =>
[Session_observe2:teacherpresent2] =>
[Session_observe2:encourage_platform2] =>
[Session_observe2:encourage_classdisc2] =>
[Session_observe2:mothertongue_teacher2] =>
[Session_observe2:teacher_handbook2] =>
[Session_observe2:Teacher_prepared2] =>
[teacher_feedback2] =>
[FSP_feedback2] =>
[TPD_certification:tcher_TPD] =>
[TPD_certification:certification_course_tchr_suport] =>
[teachersupport_moduleImplement2] =>
[school_location:Latitude] => 23.7428370300
[school_location:Longitude] => 92.7227306900
[school_location:Altitude] => 1014.0000000000
[school_location:Accuracy] => 18.0000000000
[generated_note_name_110] =>
[meta:instanceID] => uuid:2568400e-0ec3-421d-94bc-10653732e6d2
)
I want some key-value pairs from this array for data analysis and visualization. the output should look something like this:-
array(
[CLIx_code] => 1009
[state_entry] => 1
[district_entry] => 3
...
)
Basically, I want an array with a few key value pairs filtered on which I can operate some mathematical functions and pass those to D3.js for data visualization.
I tried it this way:
for ($i=0;$i<count($all_rows);$i++){
$filteredarray[] = array($all_rows[$i]['CLIx_code'], $all_rows[$i]['state_entry'], $all_rows[$i]['district_entry']);
}`
But I want key value pairs not only the value I even tried using array_filter().
I have to assume you know the key names for the elements that you want to retain and run calculations on, so array_intersect_key() is the right tool for the job.
Code (Demo):
$array=[
'logo'=>'',
'starting'=>'',
'prelim_info'=>'',
'state_entry'=>1,
'district_entry'=>3,
'CLIx_code'=>1009
// ... more elements
];
$filterkeys=[
'state_entry',
'district_entry',
'CLIx_code'
// ... more key names
];
var_export(array_intersect_key($array,array_flip($filterkeys)));
Output:
array (
'state_entry' => 1,
'district_entry' => 3,
'CLIx_code' => 1009,
)
Alternatively, you can drop the array_flip() call if you set your $filterkeys key names as keys, like this:
$filterkeys=[
'state_entry'=>'',
'district_entry'=>'',
'CLIx_code'=>''
// ... more key names
];
var_export(array_intersect_key($array,$filterkeys));
PHP: How to use array_filter() to filter array keys?
Just refer this Question's answer
Like in your case you need to write some code like below:-
<?php
//You have below array including all keys
$result_array = array('logo'=>'test','state_id'=>125,'prelim_info'=>'','CLIxModule_Impl'=>'5','district_entry'=>3);
// Now provide only those keys which you need to filter.
$filter_keys = array('district_entry','state_id');
$filtered_array = array_filter($result_array,
function ($key) use ($filter_keys) {
return in_array($key, $filter_keys);
},
ARRAY_FILTER_USE_KEY
);
var_dump($filtered_array);
?>
I am trying to access the following and need to get the value of [vid] array cell.
FieldCollectionItemEntity Object
(
[fieldInfo:protected] =>
[hostEntity:protected] => stdClass Object
(
**[vid]** => 119
[uid] => 1
[title] => My Page Name
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[vuuid] => 3304d1cf-e3cf-4c5a-884a-4abb565ddced
[nid] => 119
[type] => subpage
[language] => und
[created] => 1408621327
[changed] => 1408640191
[tnid] => 0
[translate] => 0
[uuid] => 39145013-6637-4062-96e7-1b4589609c4f
[revision_timestamp] => 1408640191
I tried the following, but I guess I don't have a clue from here:-
$mything = new myClass;
print $mything->accessObjectArray();
class myClass {
protected $var;
function accessObjectArray(){
return $this-> $var;
}
//other member functions
}
Update
I actually only have access to the variable $content which has the following multi-dimensional arrays. All I want is to get the array cell's value of [vid].
To do that, I could print $content["field_image_title"]["#object"] but after that it's protected. That's where I am wondering that how can I access this array. I unfortunately do not have access FieldCollectionItemEntity to include in my page.
On doing this:- I get the following output:-
print_r($content);
Array
(
[field_image_title] => Array
(
[#theme] => field
[#weight] => 0
[#title] => Image Title
[#access] => 1
[#label_display] => hidden
[#view_mode] => full
[#language] => und
[#field_name] => field_image_title
[#field_type] => text
[#field_translatable] => 0
[#entity_type] => field_collection_item
[#bundle] => field_image_collection
[#object] => FieldCollectionItemEntity Object
(
[fieldInfo:protected] =>
[hostEntity:protected] => stdClass Object
(
[vid] => 119
[uid] => 1
[title] => My Page Name
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[vuuid] => 3304d1cf-e3cf-4c5a-884a-4abb565ddced
[nid] => 119
[type] => subpage
[language] => und
[created] => 1408621327
[changed] => 1408640191
[tnid] => 0
[translate] => 0
[uuid] => 39145013-6637-4062-96e7-1b4589609c4f
[revision_timestamp] => 1408640191
[revision_uid] => 1
"$this-> $var;" this mean variable variable, and this throw php notice undefined variable $var,
you have to use
return $this->var;
or
return $this->vid
what your are doing with this:
return $this-> $var;
is accessing a property named after what is contained in your $var variable which does not contain anything in the scope where it is defined. pass it as a function argument:
function accessObjectArray($var){
return $this-> $var;
}
print $mything->accessObjectArray('vid');
but in any event, that won't work either since (as mentioned by #MikeBrant) you have an object in your parent object properties. something like this might work better
$o = new FieldCollectionItemEntity() // assumes this will construct the object in the state you have posted it
$o->accessObjectArray('hostEntity')->accessObjectArray('vid');
note that the method accessObjectArray($var) must be defined in both objects for this to work
the idea of a protected property is to prevent what you want to actually happen. But! protected means that only the class and it's extending classes can access a value. Make your own class that extends the other one:
class myClass extends FieldCollectionItemEntity {
function accessParentProtectedVars($var){
return $this->hostEntity->$var;
}
//other member functions
}
then your accessObjectArray() function will be able to acces the protected property. note that it's hardcoded to access the hostEntity object.
but seriously, you may want to consult the creator of the other class and maybe you will devise a way to best manage this. My proposed solution is not that much of a good practice if I daresay.
Answer for Drupal members as rendered array in the question looks like Drupal array
I believe you don't need a new class at all, you only need to get node's objects. So, below one line will work for you.
$parent_node = menu_get_object();
Now, you can access by $parent_node->vid
I have a data that came from a session and I want to parse base on regex. Below are the 3 data that I want to get login, firstName and lastName.
login = James
firstName = James.S
lastName = Steal
Array (
[user] => __PHP_Incomplete_Class Object (
[__PHP_Incomplete_Class_Name] => DEX_User
[permissionID:DE_User:private] => 9
[login:DE_User:private] => James.S
[email:DE_User:private] => james.s#domain.com
[firstName:DE_User:private] => James
[lastName:DE_User:private] => Steal
[title:DE_User:private] => Warehouse Man
[manager:DE_User:private] => Manager's Name
[workPhone:DE_User:private] => +1 (111) 111-1111
[mobilePhone:DE_User:private] => +1 (222) 222-2222
[homePhone:DE_User:private] => +1 (333) 333-3333
[im:DE_User:private] =>
[timeDelta:DE_User:private] => Asia/Hongkong
[lastLogin:DE_User:private] => __PHP_Incomplete_Class Object (
[__PHP_Incomplete_Class_Name] => GB_Date
[valueStored:protected] => 13545544126666309821
[mode:protected] => BASE
[master:protected] =>
)
[description:DE_User:private] => Warehouse Engineer
[isActive:DE_User:private] => __PHP_Incomplete_Class Object (
[__PHP_Incomplete_Class_Name] => GB_Boolean
[valueStored:protected] => 1
[mode:protected] => BASE
[master:protected] =>
)
[isTerminate:DE_User:private] => __PHP_Incomplete_Class Object (
[__PHP_Incomplete_Class_Name] => GB_Boolean
[valueStored:protected] =>
[mode:protected] => BASE
[master:protected] =>
)
[id:protected] => 231968
[isModifyed:protected] =>
[needInsert:protected] =>
[isDeleted] =>
[isRemoved] =>
)
[enter_password] => 2asas(qwqw)
I tried to perform regexp '/\[[\/]?[A-Za-z0-9]+\]/'; but i can only get that inside the bracket.
Thank you.
Instead of parsing it using RegExp you may evaluate it.
Take a look at var_export($_SESSION['user']); . This returns a parseable string, the only problem you will see there is :
__PHP_Incomplete_Class::__set_state
"__PHP_Incomplete_Class" means, the class was unknown when the Session was started, the string still can't be parsed.
But you can take the string returned by var_export($_SESSION['user'],true) , replace the occurences of __PHP_Incomplete_Class::__set_state with array and the string can be evaluated:
eval('$user='.str_replace('__PHP_Incomplete_Class::__set_state',
'array',
var_export($_SESSION['user'],true)).';');
echo $user[0]['login'].',<br/>'.
$user[0]['firstName'].',<br/>'.
$user[0]['lastName'];
I'm playing around with a zencart trying to make it do what I want but I've run out of ideas of what to Google.
When I query the DB using the zencart function the software returns an object which looks like:
queryFactoryResult Object
(
[is_cached] =>
[resource] => Resource id #117
[cursor] => 11
[EOF] =>
[fields] => Array
(
[products_id] => 5582
[products_description] => description here
[products_name] => Lucky magnet – Each petal...
[products_type] => 1
[products_quantity] => 0
[products_image] => EachPetalMag.jpg
[products_price] => 3.4000
[products_status] => 1
[products_ordered] => 14
[master_categories_id] => 21
[supplier_id] => 7
)
)
I have to loop through once to count how many master_categories are there before I can do anything else:
while (!$products->EOF) {
$products_count++;
$supcats[$products->fields['master_categories_id']] = $products->fields['master_categories_id'];
$products->MoveNext();
}
I then need to loop through the object again using the while loop like above, I've tried:
reset($products);
and
$products->EOF = FALSE;
but they don't work. Is there a way to do this with out having to send the query again?
Regular array-like operations on Zen Cart queryFactoryResult won't work as it's not an array, so this won't work:
reset($products);
To loop through the variable again use queryFactoryResult->Move(row_number) method:
$products->Move(0);
I am using the following PHP code...
$settings[] = get_app_settings();
echo $settings['weight_unit'];
but its throwing error 'undefined index'.
and when i do print_r($settings); it generates following...
Array ( [0] => Array ( [support_email] => info#domain.com [support_phone] => 9812345678 [currency_symbol] => $ [weight_unit] => g. [catalogue_image_width] => 450 [catalogue_image_height] => 675 [single_product_image_width] => 500 [single_product_image_height] => 500 [product_image_width] => 200 [product_image_height] => 200 [tax_rate] => 1 [shipping_charges] => 0 ) )
Why is it not returning a value for $settings['weight_unit']; ?
its solved by removing [](array) from $settings. thanks anyways.
Try $settings = get_app_settings(); - you probably want to assign the returned array directly and not to a new array element in $settings.